SpiderMonkey Newsletter (Firefox 104-105)

SpiderMonkey is the JavaScript engine used in Mozilla Firefox. This newsletter gives an overview of the JavaScript and WebAssembly work we’ve done as part of the Firefox 104 and 105 Nightly release cycles.

👷🏽‍♀️ New features

  • We’ve implemented the ShadowRealms proposal (disabled by default).
  • We’ve shipped the array findLast and findLastIndex functions (Firefox 104).
  • We’ve removed range restrictions from various Intl objects to match spec changes.

Features that are in progress:

  • We’ve started to implement the decorator proposal.
  • We implemented more instructions for the Wasm GC proposal (disabled by default).
  • We implemented more instructions and optimizations for the Wasm function references proposal (disabled by default).
  • We removed support for Wasm runtime types because this was removed from the spec.

⚙️ Modernizing JS modules

We’re working on improving our implementation of modules. This includes supporting modules in Workers, adding support for Import Maps, and ESMification (replacing the JSM module system for Firefox internal JS code with standard ECMAScript modules).

  • See the AreWeESMifiedYet website for the status of ESMification.
  • We’ve ported the module implementation from self-hosted JS to C++.
  • We’ve made a lot of changes to the rewritten code to match the latest version of the spec better.

💾 Robust Caching

We’re working on better (in-memory) caching of JS scripts based on the new Stencil format. This will let us integrate better with other resource caches used in Gecko, hit the cache in more cases, and will open the door to potentially cache JIT-related hints.

The team is currently working on removing the dependency on JSContext for off-thread parsing. This will make it easier to integrate with browser background threads and will further simplify the JS engine.

  • We’ve introduced ErrorContext for reporting errors without using JSContext.
  • We’re now using ErrorContext to report out-of-memory exceptions in the frontend.
  • We’re now using ErrorContext to report allocation-overflow exceptions in the frontend.
  • We’ve changed the over-recursion checks in the frontend to not depend on JSContext.

🚀 Performance

  • We optimized and reduced the size of Wasm metadata.
  • We optimized StringBuffer by reducing the number of memory (re)allocations.
  • The performance team added SIMD optimizations to speed up some string and array builtins.
  • We optimized iterators used in self-hosted code to avoid some extra allocations.
  • We optimized the object allocation code more. This made the JSON parsing benchmark more than 30% faster.
  • We fixed some places to avoid unnecessary GC tenuring.
  • We implemented a simpler heuristic for the GC heap limit and resizing (disabled by default).
  • We fixed a performance cliff for certain objects with sparse elements.
  • We added some optimizations to inline the string startsWith and endsWith functions in the JIT in certain cases.
  • We optimized the code generated for string substring operations.
  • We changed our optimizing compiler to use frame pointer relative addressing (instead of stack pointer relative) for JS and Wasm code on x86/x64.
  • We added a browser pref (disabled by default) for disabling Spectre JIT mitigations in isolated Fission content processes.

📚 Miscellaneous

  • We fixed some issues with instant evaluation in the web console, to avoid unwanted side-effects from higher order self-hosted functions.
  • The profiler team has added labels to more builtin functions.
  • We fixed a bug that could result in missing stack frames in the profiler.
  • We simplified our telemetry code to be less error-prone and easier to work with.
  • We improved Math.pow accuracy for large exponents.
  • We removed the unmaintained TraceLogger integration.
  • We updated our copy of irregexp to the latest upstream code.
  • We added more linting and code formatting for self-hosted code.
  • We changed non-Wasm SharedArrayBuffer to use calloc instead of mapped memory. This uses less memory and avoids out-of-memory exceptions in some cases.