News for hackers. Stuff that matters.
Re:The TypeScript compiler is now implemented internally wit... by KingOfCoders on Wednesday November 02, 2022 @02:25PM (#33440610)
I don't care. I care when it's implemented in Rust. We've seen reimplemtation of WebPack (in it's function as a transpiler) et al. in something faster than Javascript. And I hope there is a trend to decouple the language of the compiler from the language.
Re:The TypeScript compiler is now implemented internally wit... by TAForObvReasons on Wednesday November 02, 2022 @02:32PM (#33440751)
In every single one of these cases, it begs the question whether "JS" is the problem or "backwards compatibility". There are a huge number of inefficiencies that can be fixed with a full rewrite.

There was a recent conversation over ViteJS (a pure JS bundler) vs rust-based tooling, and when you dig into the numbers the real difference is SWC vs Babel. It raises the question whether a new transpiler written in JS can be competitive with Rust, but it's unclear if anyone tried.

Re:The TypeScript compiler is now implemented internally wit... by ppseafield on Wednesday November 02, 2022 @02:43PM (#33440897)
SWC is written in rust, and Babel is written in javascript, so you've proven the OP's point. Vite can be configured to use SWC.

The recent conversation was about Vercel benchmarking a tuned Turbopack+SWC vs. a default Vite+Babel, not really an apples to apples comparison. When Vite is configured to use SWC as a compiler, Vite's HMR gets faster; but it's not the default for compatibility reasons.

Re:The TypeScript compiler is now implemented internally wit... by longrod on Wednesday November 02, 2022 @02:49PM (#33441016)
Sucrase is faster or really close to SWC (see rhe benchmarks https://github.com/alangpierce/sucrase). Everyone still uses Babel because of the transforms.

And yes, Babel can also be made faster if enough effort is dedicated into it. it's not an impossible feat.

Re:The TypeScript compiler is now implemented internally wit... by ppseafield on Wednesday November 02, 2022 @03:04PM (#33441268)
For single core benchmarks only, correct?
Re:The TypeScript compiler is now implemented internally wit... by RyanCavanaugh on Wednesday November 02, 2022 @02:50PM (#33441046)
Sucrase is written in JS and boasts the highest line throughput of any competing transpiler

https://github.com/alangpierce/sucrase

            Time            Speed
Sucrase 0.57 seconds 636975 lines per second

swc 1.19 seconds 304526 lines per second

esbuild 1.45 seconds 248692 lines per second

TypeScript 8.98 seconds 40240 lines per second

Babel 9.18 seconds 39366 lines per second

Re:The TypeScript compiler is now implemented internally wit... by merb on Wednesday November 02, 2022 @02:59PM (#33441199)
but the benchmark is stupid: https://github.com/alangpierce/sucrase/blob/main/benchmark/b...

> Like all JavaScript code run in V8, Sucrase runs more slowly at first, then gets faster as the just-in-time compiler applies more optimizations. From a rough measurement, Sucrase is about 2x faster after running for 3 seconds than after running for 1 second. swc (written in Rust) and esbuild (written in Go) don't have this effect because they're pre-compiled, so comparing them with Sucrase gets significantly different results depending on how large of a codebase is being tested and whether each compiler is allowed a "warm up" period before the benchmark is run.

(worse it disables esbuild and swc's multi-threading... https://github.com/alangpierce/sucrase/blob/main/benchmark/b... https://github.com/alangpierce/sucrase/blob/main/benchmark/b...)

fake it till ya make it.

it's like saying "if I disable everything and wait for 5 minutes it's faster"

Re:The TypeScript compiler is now implemented internally wit... by RyanCavanaugh on Wednesday November 02, 2022 @03:25PM (#33441578)
I don't see how this is a rebuttal to the claim. 636,975 is more than 2x 304,526, so assuming the quoted paragraph is correct, sucrase is still the highest-throughput transpiler even during its warm-up phase. Probably this isn't true for the first 100 milliseconds of execution during the very first warm-up stages, but if the transpile phase is that short, it's basically irrelevant anyway.
Re:The TypeScript compiler is now implemented internally wit... by merb on Wednesday November 02, 2022 @03:41PM (#33441808)
the warm-up phase is the whole reason why esbuild and swc exists btw. and also the sample is basically a small hello world. any real project would do a little more and the jit would not optimize as much.

also 2x 300k is not really the way how multi-threading works... especially not golang, which should not be run with GOMAXPROCS=1

Re:The TypeScript compiler is now implemented internally wit... by cxr on Wednesday November 02, 2022 @05:53PM (#33443417)
As far as I can follow your argument, it seems to be that the native tools perform better on the small inputs (that only ever take a second or three to complete), and that the creators ("maintainers"?) of Sucrase have their thumb on the scale or something, since they emphasize in their results the very large inputs that will involve longer running jobs where their tool has had a chance to warm up. In other words, the tools you're defending only do better when it doesn't really matter, and the tool you're downplaying outperforms the competition on the jobs where it actually does matter. If anything is backwards (or "stupid", as you put it) then that seems to be it.

Maybe I'm misunderstanding. In that case, please provide a better benchmark.

Re:The TypeScript compiler is now implemented internally wit... by alangpierce on Wednesday November 02, 2022 @07:46PM (#33444507)
Hi, Sucrase author here.

To be clear, the benchmark in the README does not allow JIT warm-up. The Sucrase numbers would be better if it did. From testing just now (add `warmUp: true` to `benchmarkJest`), Sucrase is a little over 3x faster than swc if you allow warm-up, but it seemed unfair to disregard warm-up for the comparison in the README.

It's certainly fair to debate whether 360k lines of code is a realistic codebase size for the benchmark; the higher-scale the test case, the better Sucrase looks.

> worse it disables esbuild and swc's multi-threading

At some point I'm hoping to update the README benchmark to run all tools in parallel, which should be more convincing despite the added variability: https://github.com/alangpierce/sucrase/issues/730 . In an ideal environment, the results are pretty much the same as a per-core benchmark, but I do expect that Node's parallelism overhead and the JIT warm-up cost across many cores would make Sucrase less competitive than the current numbers.

Re:The TypeScript compiler is now implemented internally wit... by KingOfCoders on Thursday November 03, 2022 @01:13AM (#33447288)
"Tools run in single-threaded mode without warm-up."

Ithought it was 2022. I have a 12 core machine and my next machine will probably have 22 cores.

But I'm amazed, transpiling 636975 lines in <1 second is nice.

[Edit] What I do not understand is "Sucrase does not check your code for errors." So it's not a type checker? Or does it check type errors? Why would I used it for Typescript when the reason to use TS is to add types to JS to prevent errors?

Is this more like Rust check for continous work and then use tsc from time to time to check for errors?

Re:The TypeScript compiler is now implemented internally wit... by alangpierce on Thursday November 03, 2022 @03:38AM (#33448111)
Like any transpiler, Sucrase can be run in parallel by having the build system send different files to different threads/processes. Sucrase itself it more of a primitive, just a plain function from input code to output code.

> What I do not understand is "Sucrase does not check your code for errors." So it's not a type checker?

That's correct, Sucrase, swc, esbuild, and Babel are all just transpilers that transform TypeScript syntax into plain JavaScript (plus other transformations). The usual way you set things up is to use the transpiler to run and build your TS code, and you separately run type checking using the official TypeScript package.

Re:The TypeScript compiler is now implemented internally wit... by svnpenn on Wednesday November 02, 2022 @02:31PM (#33440738)
thats pretty harsh. I dont even like TypeScript/JavaScript, but these are some pretty good numbers:

> The compiler is now 10-25% faster. `tsc` is now 30% faster to start. Our npm package is now 43% smaller. More improvements are in the works.

Re:The TypeScript compiler is now implemented internally wit... by speedgoose on Wednesday November 02, 2022 @02:42PM (#33440891)
I think tooling of one programming language should be written in the programming language. Otherwise the community will hardly be involved.

All these rust tools may be slight faster, but typescript developers will not learn rust to improve the typescript compiler.

Re:The TypeScript compiler is now implemented internally wit... by berkes on Wednesday November 02, 2022 @03:16PM (#33441441)
If you think of typescript as "tooling" that makes sense.

But if you think of it as compiler, or transpiler, not so much. Python, Ruby etc "compilers" (runtimes, really) aren't written in Python or Ruby. Or rather, there are alternatives around, but they aren't the fastest nor the best. Such "tools" are built in C. As are compilers for C++, Rust or most languages really.

Re:The TypeScript compiler is now implemented internally wit... by speedgoose on Wednesday November 02, 2022 @03:39PM (#33441787)
I understand your point. Compilers and interpreters are traditionally written in C/C++, but we don't have to do the same than before.
Re:The TypeScript compiler is now implemented internally wit... by llanowarelves on Wednesday November 02, 2022 @02:47PM (#33440984)
What's the conversion rate on that though?

For smaller languages that are much less supported that makes much more sense.

For bigger languages we treat it much more as a black box.

Re:The TypeScript compiler is now implemented internally wit... by satvikpendem on Wednesday November 02, 2022 @05:43PM (#33443308)
> but typescript developers will not learn rust to improve the typescript compiler.

Why not? TS has much more in common with Rust than with JS, in terms of typing. Compiler engineers are not that prevalent in the community, but they are much more prevalent in the systems engineering world which Rust is a part of, so I'd assume it's actually more beneficial to have a compiler in Rust than in TS because it would mean more people interested in contributing.

Re:The TypeScript compiler is now implemented internally wit... by shepherdjerred on Wednesday November 02, 2022 @08:34PM (#33445018)
> TS has much more in common with Rust than with JS, in terms of typing.

TS has much more in common with JS than it does with Rust in every other comparison

Every TS dev will know at least a little bit of JS. Not every TS dev will know Rust at all. They're very different languages.

Re:The TypeScript compiler is now implemented internally wit... by satvikpendem on Wednesday November 02, 2022 @08:51PM (#33445171)
Compiler engineers will be far more familiar with Rust, C++, C and other similar languages than with JS, so it doesn't really matter whether TS and JS are similar as long as compiler engineers can use their preferred language to build the compiler.
Re:The TypeScript compiler is now implemented internally wit... by Kyza on Wednesday November 02, 2022 @02:47PM (#33440981)
I think a performance improvement in anything existing is great. Especially for something as big as TSC. It has such a large amount of usage that many people will appreciate. While it would be great to have it reimplemented effectively in something inherently faster, not improving what we have while it's clearly still the best option wouldn't be helpful.
Re:The TypeScript compiler is now implemented internally wit... by shepherdjerred on Wednesday November 02, 2022 @08:37PM (#33445048)
> I don't care. I care when it's implemented in Rust.

What does this add to the discussion? This comment serves nothing except to be negative to an author who has made a great improvement.