SpiderMonkey explained
SpiderMonkey is an open-source JavaScript and WebAssembly engine by the Mozilla Foundation.[3]
It is the first JavaScript engine, written by Brendan Eich at Netscape Communications, and later released as open source and currently maintained by the Mozilla Foundation. It is used in the Firefox web browser.
History
Eich "wrote JavaScript in ten days" in 1995,[4] having been "recruited to Netscape with the promise of 'doing Scheme' in the browser".[5] (The idea of using Scheme was abandoned when "engineering management [decided] that the language must 'look like Java.)[5] In late 1996, Eich, needing to "pay off [the] substantial technical debt" left from the first year, "stayed home for two weeks to rewrite Mocha as the codebase that became known as SpiderMonkey".[4] (Mocha was the original working name for the language.)[6] In 2011, Eich transferred management of the SpiderMonkey code to Dave Mandelin.[4]
Versions
SpiderMonkey version historyVersion | Release date | Corresponding ECMAScript version | Browser version | Added functionality |
---|
March 1996 | | Netscape Navigator 2.0 | |
---|
August 1996 | | Netscape Navigator 3.0 | |
---|
June 1997 | | Netscape Navigator 4.0 - 4.05 | |
---|
October 1998 | ECMA-262 1st + 2nd edition | Netscape Navigator 4.06-4.7x | |
---|
| | Netscape Server | |
---|
November 2000 | ECMA-262 3rd edition | Netscape Navigator 6, Firefox 1.0 | |
---|
November 2005[7] | | Firefox 1.5 | additional array methods, array and string generics, E4X |
---|
October 2006 | | Firefox 2.0 | iterators and generators, let statement, array comprehensions, destructuring assignment |
---|
June 2008 | | Firefox 3.0 | generator expressions, expression closures |
---|
March 2011 | ECMA-262 5th edition | Firefox 4.0 | JSON support |
---|
January 2012 | | Firefox 10.0 | |
---|
November 2012 | | Firefox 17.0 | |
---|
September 2013 | | Firefox 24.0 | |
---|
July 2014 | | Firefox 31.0 | |
---|
May 2015 | | Firefox 38.0 | |
---|
March 2016 | | Firefox 45.0 | |
---|
March 2017 | | Firefox 52.0 | |
---|
May 2018 | | Firefox 60.0 | |
---|
July 2019 | | Firefox 68.0 | |
---|
June 2020 | | Firefox 78.0 | |
---|
August 2021 | | Firefox 91.0 | |
---|
June 2022 | | Firefox 102.0 | |
---|
July 2022 | | Firefox 103.0 | | |
---|
Standards
SpiderMonkey implements the ECMA-262 specification (ECMAScript). ECMA-357 (ECMAScript for XML (E4X)) was dropped in early 2013.[8]
Internals
SpiderMonkey is written in C/C++ and contains an interpreter, the IonMonkey JIT compiler, and a garbage collector.
TraceMonkey
TraceMonkey[9] was the first JIT compiler written for the JavaScript language. Initially introduced as an option in a beta release and introduced in Brendan Eich's blog on August 23, 2008,[10] the compiler became part of the mainline release as part of SpiderMonkey in Firefox 3.5, providing "performance improvements ranging between 20 and 40 times faster" than the baseline interpreter in Firefox 3.[11]
Instead of compiling whole functions, TraceMonkey was a tracing JIT, which operates by recording control flow and data types during interpreter execution. This data then informed the construction of trace trees, highly specialized paths of native code.
Improvements to JägerMonkey eventually made TraceMonkey obsolete, especially with the development of the SpiderMonkey type inference engine. TraceMonkey is absent from SpiderMonkey from Firefox 11 onward.[12]
JägerMonkey
JägerMonkey, internally named MethodJIT, was a whole-method JIT compiler designed to improve performance in cases where TraceMonkey could not generate stable native code.[13] [14] It was first released in Firefox 4 and eventually entirely supplanted TraceMonkey. It has itself been replaced by IonMonkey.
JägerMonkey operated very differently from other compilers in its class: while typical compilers worked by constructing and optimizing a control-flow graph representing the function, JägerMonkey instead operated by iterating linearly forward through SpiderMonkey bytecode, the internal function representation. Although this prohibits optimizations that require instruction reordering, JägerMonkey compiling has the advantage of being very fast, which is useful for JavaScript since recompiling due to changing variable types is frequent.
Mozilla implemented a number of critical optimizations in JägerMonkey, most importantly polymorphic inline caches and type inference.[15]
The difference between TraceMonkey and JägerMonkey JIT techniques and the need for both was explained in a hacks.mozilla.org article. A more in-depth explanation of the technical details was provided by Chris Leary, one of SpiderMonkey's developers, in a blog post . More technical information can be found in other developer's blogs: dvander, dmandelin.
IonMonkey
IonMonkey was a JavaScript JIT compiler of Mozilla, which was aimed to enable many new optimizations that were impossible with the prior JägerMonkey architecture.[16]
IonMonkey was a more traditional compiler: it translated SpiderMonkey bytecode into a control-flow graph, using static single assignment form (SSA) for the intermediate representation. This architecture enabled well-known optimizations from other programming languages to be used for JavaScript, including type specialization, function inlining, linear-scan register allocation, dead code elimination, and loop-invariant code motion.[17]
The compiler can emit fast native code translations of JavaScript functions on the ARM, x86, and x86-64 platforms. It has been the default engine since Firefox 18.[18]
OdinMonkey
OdinMonkey is the name of Mozilla's new optimization module for asm.js, an easily compilable subset of JavaScript. OdinMonkey itself is not a JIT compiler, it uses the current JIT compiler. It's included with Firefox from release 22.
WarpMonkey
The WarpMonkey JIT replaces the former IonMonkey engine from version 83.[19] It is able to inline other scripts and specialize code based on the data and arguments being processed.It translates the bytecode and Inline Cache data into a Mid-level Intermediate Representation (Ion MIR) representation. This graph is transformed and optimized before being lowered to a Low-level Intermediate Representation (Ion LIR). This LIR performs register allocation and then generates native machine code in a process called Code Generation.The optimizations here assume that a script continues to see data similar what has been seen before. The Baseline JITs are essential to success here because they generate ICs that match observed data. If after a script is compiled with Warp, it encounters data that it is not prepared to handle it performs a bailout. The bailout mechanism reconstructs the native machine stack frame to match the layout used by the Baseline Interpreter and then branches to that interpreter as though we were running it all along. Building this stack frame may use special side-table saved by Warp to reconstruct values that are not otherwise available.[20]
Use
SpiderMonkey is intended to be embedded in other applications that provide host environments for JavaScript. An incomplete list follows:
- Mozilla Firefox, Thunderbird, SeaMonkey, and other applications that use the Mozilla application framework
- Data storage applications:
- MongoDB moved from V8 to SpiderMonkey in version 3.2[21]
- Riak uses SpiderMonkey as the runtime for JavaScript MapReduce operations[22]
- CouchDB database system (written in Erlang). JavaScript is used for defining maps, filters, reduce functions and viewing data, for example in HTML format.
- Adobe Acrobat and Adobe Reader, Adobe Flash Professional, and Adobe Dreamweaver. Adobe Acrobat DC uses Spidermonkey 24.2 with ECMA-357 support forward ported.[23]
- GNOME desktop environment, version 3 and later
- Yahoo! Widgets, formerly named Konfabulator
- FreeSWITCH, open-source telephony engine, uses SpiderMonkey to allow users to write call management scripts in JavaScript
- PythonMonkey uses SpiderMonkey to allow users to write programs where JavaScript and Python functions, types, and events interoperate and (where possible) share memory storage. [24]
- The text-based web browser ELinks uses SpiderMonkey to support JavaScript[25]
- Parts of SpiderMonkey are used in the Wine project's JScript (re-)implementation[26]
- Synchronet, a BBS, e-mail, Web, and application server using the SpiderMonkey engine
- JavaScript OSA, a SpiderMonkey inter-process communication language for the Mac computer
- 0 A.D., a real-time strategy game
- Wasmer has incorporated SpiderMonkey into their WinterJS open-source project; a JavaScript runtime environment.
- SpiderMonkey is also used in many other open-source projects; an external list is maintained at Mozilla's developer site.[27]
SpiderMonkey includes a JavaScript Shell for interactive JavaScript development and for command-line invocation of JavaScript program files.[28]
See also
External links
Notes and References
- Web site: 1.8.8 – SpiderMonkey | MDN . Developer.mozilla.org . 10 January 2013 . 21 March 2013 . https://web.archive.org/web/20130502115508/https://developer.mozilla.org/en-US/docs/SpiderMonkey/1.8.8#Platform_support . 2 May 2013 . live . dmy-all .
- Web site: 2023-02-16. SpiderMonkey Newsletter (Firefox 110-111) . spidermonkey.dev . 27 December 2023.
- Web site: Home. 2023-04-24. SpiderMonkey JavaScript/WebAssembly Engine. en-US.
- Web site: Brendan . Eich . Brendan Eich . New JavaScript Engine Module Owner . 21 June 2011 . BrendanEich.com . 1 July 2011 . https://web.archive.org/web/20110714191057/http://brendaneich.com/2011/06/new-javascript-engine-module-owner/ . 14 July 2011 . live . dmy-all.
- Web site: Popularity . 3 April 2008 . Brendan . Eich . Brendan Eich . BrendanEich.com . 1 July 2011 . https://web.archive.org/web/20110703020955/http://brendaneich.com/2008/04/popularity/ . 3 July 2011 . live . dmy-all.
- Web site: Mapping the Monkeysphere . Brendan . Eich . 19 August 2011 . Brendan Eich . 19 August 2011 . https://web.archive.org/web/20130113222435/http://blog.cdleary.com/2011/06/mapping-the-monkeysphere/#comment-222163115 . 13 January 2013 . live . dmy-all.
- Web site: New in JavaScript 1.6. dead. https://web.archive.org/web/20150905053952/https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.6. 5 September 2015. 28 July 2015. dmy-all.
- Web site: 759422 - Remove use of e4x in account creation . 5 February 2013.
- Web site: JavaScript:TraceMonkey, MozillaWiki . 2020-07-22.
- Web site: TraceMonkey: JavaScript Lightspeed, Brendan Eich's Blog . 2020-07-22.
- Web site: Firefox to get massive JavaScript performance boost . Paul . Ryan . 22 August 2008 . Ars Technica . 21 March 2013 . https://web.archive.org/web/20120506204854/http://arstechnica.com/open-source/news/2008/08/firefox-to-get-massive-javascript-performance-boost.ars . 6 May 2012 . live . dmy-all.
- Web site: SpiderMonkey is on a diet | Nicholas Nethercote . Nethercote . Nicholas . 1 November 2011 . Blog.mozilla.com . 21 March 2013 . https://web.archive.org/web/20120328124431/http://blog.mozilla.com/nnethercote/2011/11/01/spidermonkey-is-on-a-diet/ . 28 March 2012 . live . dmy-all.
- Web site: JaegerMonkey – Fast JavaScript, Always! » Mystery Bail Theater. 26 February 2010. Bailopan.net. 21 March 2013. https://web.archive.org/web/20130324172746/http://www.bailopan.net/blog/?p=683. 24 March 2013. live. dmy-all.
- Web site: Mozilla borrows from WebKit to build fast new JS engine. Paul. Ryan. 9 March 2010. Ars Technica. 21 March 2013. https://web.archive.org/web/20120416171903/http://arstechnica.com/open-source/news/2010/03/mozilla-borrows-from-webkit-to-build-fast-new-js-engine.ars. 16 April 2012. live. dmy-all.
- Web site: JaegerMonkey - MozillaWiki. Wiki.mozilla.org. 21 March 2013. https://web.archive.org/web/20130823045214/https://wiki.mozilla.org/JaegerMonkey. 23 August 2013. live. dmy-all.
- Web site: Platform/Features/IonMonkey - MozillaWiki . Wiki.mozilla.org . 11 February 2013 . 21 March 2013 . https://web.archive.org/web/20130308142525/https://wiki.mozilla.org/Platform/Features/IonMonkey . 8 March 2013 . live . dmy-all .
- Web site: IonMonkey: Mozilla’s new JavaScript JIT compiler . Infoq.com . 21 March 2013 . https://web.archive.org/web/20121208010755/http://www.infoq.com/news/2011/05/ionmonkey . 8 December 2012 . live . dmy-all .
- Web site: Firefox Notes - Desktop . Mozilla.org . 8 January 2013 . 21 March 2013 . https://web.archive.org/web/20140902235153/http://website-archive.mozilla.org/www.mozilla.org/firefox_releasenotes/en-US/firefox/18.0/releasenotes/ . 2 September 2014 . live . dmy-all .
- Web site: Warp: Improved JS performance in Firefox 83 – Mozilla Hacks - the Web developer blog. 13 November 2020. 2021-08-28. Mozilla Hacks – the Web developer blog. en-US.
- Web site: SpiderMonkey — Firefox Source Docs documentation. 2021-08-28. firefox-source-docs.mozilla.org.
- Web site: JavaScript Changes in MongoDB 3.2 — MongoDB Manual 3.4 . 23 November 2016 . https://web.archive.org/web/20170606170929/https://docs.mongodb.com/manual/release-notes/3.2-javascript/ . 6 June 2017 . live . dmy-all .
- Web site: The Release Riak 0.8 and JavaScript Map/Reduce. https://web.archive.org/web/20111103222007/http://basho.com/blog/technical/2010/02/03/the-release-riak-0.8-and-javascript-mapreduce/. 3 November 2011. live. 24 April 2011. dmy-all.
- Web site: Acrobat DC SDK Documentation. helpx.adobe.com. 5 November 2021.
- Web site: Distributive-Network/PythonMonkey: A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment. . GitHub . 2023-07-07 . . 2023-07-10.
- Web site: Bolso. Erik Inge. 2005 Text Mode Browser Roundup. Linux Journal. 5 August 2010. 8 March 2005. https://web.archive.org/web/20100315132917/http://www.linuxjournal.com/article/8148?page=0,1. 15 March 2010. live. dmy-all.
- http://www.winehq.org/pipermail/wine-cvs/2008-September/047548.html wine-cvs mailing list
- Web site: SpiderMonkey > FOSS. MDN Web Docs. en. 2019-04-02.
- Web site: Introduction to the JavaScript shell . 29 September 2010 . MDN . Mozilla Developer Network . 14 December 2010 . The JavaScript shell is a command-line program included in the SpiderMonkey source distribution. [...] You can use it as an interactive shell [...] You can also pass in, on the command line, a JavaScript program file to run [...] . https://web.archive.org/web/20110629134447/https://developer.mozilla.org/En/SpiderMonkey/Introduction_to_the_JavaScript_shell . 29 June 2011 . dead . dmy-all.