Speeding up JavaScript on Compute
JavaScript is one of the most popular programming languages today, and here at Fastly, we aim to meet developers where they are, providing the tools and technologies to develop fast, featureful applications. In 2021, we added support for running JavaScript on Compute with our JavaScript SDK. JavaScript is joined by Rust and Go in our suite of first-class supported languages today, and we continue to improve and optimize the experience.
To improve Javascript performance on our Compute product, we have developed a series of compiler optimizations in our runtime that yield a ~3x speedup on average in JavaScript execution and are otherwise fully compatible. Several customers tested this to validate the speedups, and we are now confident enough to expose the configuration and call it ready for general use. To learn more about how we made this work, read the in-depth post series on the compiler and runtime technology behind this feature (1, 2, 3).
To enable the new mode today, ensure you are using the latest version of the SDK (v3.27.0 or greater), then add –-enable-aot
to the build flags in your project’s package.json file. As always, we recommend testing significant changes before rolling them out.
For example, if your build flags looked like this before:
"build": "js-compute-runtime bin/index.js bin/main.wasm",
The resulting change would look like this:
"build": "js-compute-runtime --enable-aot bin/index.js bin/main.wasm",
That’s it! With one line of code, your project will be approximately 3x faster at runtime.
Benchmark Results
The final upstreamed PR quotes these numbers on the Octane benchmark suite tested against a variety of workloads (numbers are rates. Higher is better):
Engines running inside a Wasm module:
- existing interpreter (in production today) vs.
- ahead-of-time compilation (this post)
interpreter AOT compilation Speedup
Richards 166 729 4.39x
DeltaBlue 169 686 4.06x
Crypto 412 1255 3.05x
RayTrace 525 1315 2.50x
EarleyBoyer 728 2561 3.52x
RegExp 271 461 1.70x
Splay 1262 3258 2.58x
NavierStokes 656 2255 3.44x
PdfJS 2182 5991 2.75x
Mandreel 166 503 3.03x
Gameboy 1357 4659 3.43x
CodeLoad 19417 17488 0.90x
Box2D 927 3745 4.04x
----
Geomean 821 2273 2.77x
Overall, we saw a 2.77x geomean improvement, with a maximum of 4.39x on one benchmark and most benchmarks around 2.5x-3.5x. This also correlates with early customer testing results.
For more information on the methodology and breakdown, read up on the testing in detail here.
Add --enable-aot
to your build flags and try it yourself! When you’re testing, share your before-and-after results with the community.
If you haven’t used our Compute platform yet, you’re missing out! Sign up for a free developer account and ship your next Javascript application on a blazing-fast platform.