A while ago I said JavaScript can be as fast as Rust, and got some raised eyebrows. Fair. Here is the work behind that claim, including the parts that aren't there yet.
Announcing Perry Three.js (research preview): unmodified three.js from npm, compiled ahead of time into a native binary. No JS engine, no WebView.
macOS, Windows, Linux, iOS, iPadOS, tvOS and Android.
Our open-source three.js chess game, tuichess, is on the App Store. The store build still renders through Bloom; the fully compiled runtime is next.
Compiling three.js was never the hard part. Perry compiles pretty much any program by now. The hard part is speed, and speed hinges on one question:
can the compiler prove what a value is, at every point in the program?
Where it can, Perry emits the kind of code Rust would: direct loads, direct calls, no runtime lookups, no caches. three.js's Matrix4.multiplyMatrices,
instructions per multiply, same machine, same method:
Node: 411
Rust, Vec<f64>: 288
Perry: 237
Rust, [f64; 16]: 73
On the same data layout, a heap array with a length, Perry is ahead of Rust. The remaining 3x is mostly Rust knowing the array has exactly 16 elements. That's one more fact to prove.
That is the ceiling. A real app isn't there yet. Once the same function sits behind the full web layer (DOM, styles, Proxies), one unknown early on
spreads to everything downstream, and the compiler falls back to the generic path: ~6,000 instructions today. Same compiler, same code; the proofs just don't survive the trip yet. We call that the cliff and that is what I am currently working on. This will also be what unlocks performance for all other JS apps.
Perry Solver is how we remove it: whole-program analysis that proves facts site by site. Exact or nothing, no heuristics. Where we are today:
- Released Perry: 14-20% of sites proven on larger builds
- Solver branch: 86% on the same build
- One step up the ladder (OrbitControls + a DOM Proxy layer) the cliff is back. Root cause found, fix in progress.
- Compile times are 6-12x worse for now. Also on the list.
So: not there yet. But the gap is now a number, the number is moving, and everything is open: the source, the test ladder, the misses.
If you want to watch a compiler learn to prove JavaScript, follow along.
Links in the first reply.
Here the page about Perry three.js:
https://t.co/NAnREcKgV3
and here the app at the appstore: https://t.co/shyaXMEEfT
s/id6831127773
(Android will come too, I'm testing on an old Android and want to have the current performance finalized first)
A while ago I said JavaScript can be as fast as Rust, and got some raised eyebrows. Fair. Here is the work behind that claim, including the parts that aren't there yet.
Announcing Perry Three.js (research preview): unmodified three.js from npm, compiled ahead of time into a native binary. No JS engine, no WebView.
macOS, Windows, Linux, iOS, iPadOS, tvOS and Android.
Our open-source three.js chess game, tuichess, is on the App Store. The store build still renders through Bloom; the fully compiled runtime is next.
Compiling three.js was never the hard part. Perry compiles pretty much any program by now. The hard part is speed, and speed hinges on one question:
can the compiler prove what a value is, at every point in the program?
Where it can, Perry emits the kind of code Rust would: direct loads, direct calls, no runtime lookups, no caches. three.js's Matrix4.multiplyMatrices,
instructions per multiply, same machine, same method:
Node: 411
Rust, Vec<f64>: 288
Perry: 237
Rust, [f64; 16]: 73
On the same data layout, a heap array with a length, Perry is ahead of Rust. The remaining 3x is mostly Rust knowing the array has exactly 16 elements. That's one more fact to prove.
That is the ceiling. A real app isn't there yet. Once the same function sits behind the full web layer (DOM, styles, Proxies), one unknown early on
spreads to everything downstream, and the compiler falls back to the generic path: ~6,000 instructions today. Same compiler, same code; the proofs just don't survive the trip yet. We call that the cliff and that is what I am currently working on. This will also be what unlocks performance for all other JS apps.
Perry Solver is how we remove it: whole-program analysis that proves facts site by site. Exact or nothing, no heuristics. Where we are today:
- Released Perry: 14-20% of sites proven on larger builds
- Solver branch: 86% on the same build
- One step up the ladder (OrbitControls + a DOM Proxy layer) the cliff is back. Root cause found, fix in progress.
- Compile times are 6-12x worse for now. Also on the list.
So: not there yet. But the gap is now a number, the number is moving, and everything is open: the source, the test ladder, the misses.
If you want to watch a compiler learn to prove JavaScript, follow along.
Links in the first reply.
Here the page about Perry three.js:
https://t.co/YRaXlxMS1c
and here the app at the appstore: https://t.co/Qp7LIgFnz9
(Android will come too, I'm testing on an old Android and want to have the current performance finalized first)
I've been using X for 17 years ...
And I still don't care about how to share tweets or posts and whether or not there is a screenshot or not.
Thought y'all would like to know that about me. π
Nice!
For Perry to compile Effect properly a small change would have been helpful. So I suggested a way to do that and the AI for Effect implemented it as I suggested and it just got merged.
Thanks @EffectTS_ π
This allows better optimization for AOT.
https://t.co/xhArnCbkDK
Rust is not faster than JavaScript!
Rust is also not faster than C++.
The compiled binary code might be faster than the compiled binary code of either of the others. But that's a compiler question, not a language question.
Some languages make it easier to compile to performant code than others, but the trade-off is in the language itself.
Don't confuse language with execution.