V8 (JavaScript engine)
{{Short description|JavaScript and WebAssembly engine}}
{{For|The engine used in vehicles|V8 engine}}
{{Use dmy dates|date=March 2024}}
{{Infobox software
| name = V8
| logo = V8 JavaScript engine logo 2.svg
| logo size = 64px
| screenshot =
| caption =
| developer = Google{{cite web |title=Documentation · V8 |url=https://v8.dev/docs |publisher=Google |access-date=3 March 2024}}
| released = {{start date and age|2008|9|2|df=y}}
| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}
| programming language = C++
| platform = IA-32, x86-64, 32-bit ARM, AArch64, 32-bit MIPS, MIPS64, PowerPC, IBM ESA/390, z/Architecture
| genre = JavaScript and WebAssembly engine
| license = BSD{{cite web|url=https://github.com/v8/v8/blob/master/LICENSE.v8|title=v8/LICENSE.v8 at master|publisher=Github}}
}}
V8 is a JavaScript and WebAssembly engine developed by Google for its Chrome browser.{{cite web |last=Lenssen |first=Philipp |date=1 September 2008 |title=Google on Google Chrome - comic book |url=http://blogoscoped.com/google-chrome/ |url-status=live |access-date=17 August 2010 |work=Google Blogoscoped |language=en-US}} V8 is free and open-source software that is part of the Chromium project and also used separately in non-browser contexts, notably the Node.js runtime system. Other server-side JavaScript runtimes use alternative engines, such as Bun (which uses JavaScriptCore) and Hermes (used by React Native).
History
Google created V8 for its Chrome browser, and both were first released in 2008. The lead developer of V8 was Lars Bak, and it was named after the powerful car engine.{{cite web |title=V8: an open source JavaScript engine |url=https://www.youtube.com/watch?v=hWhMKalEicY |website=YouTube | date=15 September 2008 |publisher=Google |access-date=15 March 2024}} For several years, Chrome was faster than other browsers at executing JavaScript.{{cite web|url=https://www.pcgameshardware.com/aid,687738/Big-browser-comparison-test-Internet-Explorer-vs-Firefox-Opera-Safari-and-Chrome-Update-Firefox-35-Final/Practice/|title=Big browser comparison test: Internet Explorer vs. Firefox, Opera, Safari and Chrome|work=PC Games Hardware|date=3 July 2009|publisher=Computec Media AG|access-date=June 28, 2010|archive-date=May 2, 2012|archive-url=https://web.archive.org/web/20120502043027/http://www.pcgameshardware.com/aid,687738/Big-browser-comparison-test-Internet-Explorer-vs-Firefox-Opera-Safari-and-Chrome-Update-Firefox-35-Final/Practice/|url-status=dead}}{{cite web | url=https://lifehacker.com/lifehacker-speed-tests-safari-4-chrome-2-and-more-5286869 | title=Lifehacker Speed Tests: Safari 4, Chrome 2 | first=Kevin | last=Purdy | work=Lifehacker | date=June 11, 2009 | access-date=May 8, 2021 | archive-date=April 14, 2021 | archive-url=https://web.archive.org/web/20210414095403/https://lifehacker.com/lifehacker-speed-tests-safari-4-chrome-2-and-more-5286869 | url-status=live }}{{cite magazine |title=Mozilla asks, 'Are we fast yet?' |url=https://www.wired.com/2010/09/mozilla-asks-are-we-fast-yet/ |magazine=Wired |access-date=January 18, 2019 |archive-date=June 22, 2018 |archive-url=https://web.archive.org/web/20180622213244/https://www.wired.com/2010/09/mozilla-asks-are-we-fast-yet/ |url-status=live }}
The V8 assembler is based on the Strongtalk assembler.{{cite web|url=https://code.google.com/p/v8/source/browse/trunk/LICENSE |title=V8 JavaScript Engine: License |work=Google Code |access-date=17 August 2010 |url-status=dead |archive-url=https://web.archive.org/web/20100722105022/http://code.google.com/p/v8/source/browse/trunk/LICENSE |archive-date=July 22, 2010 }} On 7 December 2010, a new compiling infrastructure named Crankshaft was released, with speed improvements.{{cite web |url=https://blog.chromium.org/2010/12/new-crankshaft-for-v8.html |title=A New Crankshaft for V8 |date=7 December 2010 |work=Chromium Blog |access-date=22 April 2011}} In version 41 of Chrome in 2015, project TurboFan was added to provide more performance improvements with previously challenging workloads such as asm.js.{{cite web |url=https://blog.chromium.org/2015/07/revving-up-javascript-performance-with.html |title=Revving up JavaScript performance with TurboFan |date=7 July 2015 |access-date=5 March 2016}} Much of V8's development is strongly inspired by the Java HotSpot Virtual Machine developed by Sun Microsystems, with the newer execution pipelines being very similar to those of HotSpot's.
Support for the new WebAssembly language began in 2015.{{cite web |title=Experimental support for WebAssembly in V8 |url=https://v8.dev/blog/webassembly-experimental |website=v8.dev |access-date=12 March 2024}}
In 2016, the Ignition interpreter was added to V8 with the design goal of reducing the memory usage on small memory Android phones in comparison with TurboFan and Crankshaft.{{cite web |url=https://www.youtube.com/watch?v=r5OWCtuKiAk |archive-url=https://ghostarchive.org/varchive/youtube/20211221/r5OWCtuKiAk |archive-date=2021-12-21 |url-status=live|title=BlinkOn 6 Day 1 Talk 2: Ignition - an interpreter for V8 |website=YouTube |date=26 June 2016 |access-date=2 September 2016}}{{cbignore}} Ignition is a register based machine and shares a similar (albeit not the exact same) design to the templating interpreter utilized by HotSpot.
In 2017, V8 shipped a brand-new compiler pipeline, consisting of Ignition (the interpreter) and TurboFan (the optimizing compiler). Starting with V8 version 5.9, Full-codegen (the early baseline compiler) and Crankshaft are no longer used in V8 for JavaScript execution, since the team believed they were no longer able to keep pace with new JavaScript language features and the optimizations those features required.{{cite web |url=https://v8project.blogspot.com/2017/05/launching-ignition-and-turbofan.html |title=Launching Ignition and TurboFan |date=16 May 2017 |access-date=13 July 2017}}
In 2021, a new tiered compilation pipeline was introduced with the release of the SparkPlug compiler, which supplements the existing TurboFan compiler within V8, in a direct parallel to the profiling C1 Compiler used by HotSpot.
In 2023, the Maglev SSA-based compiler was added, which is 10 times slower than Sparkplug but 10 times faster than TurboFan, bridging the gap between Sparkplug and TurboFan for less frequently run loops that do not get "hot" enough to be optimised by TurboFan, as is the case for most web applications that spend more time interacting with the browser than in JavaScript execution. {{cite web |url=https://v8.dev/blog/maglev |title=Maglev - V8's Fastest Optimizing JIT |date=5 December 2023|access-date=26 January 2024}}
Design
V8 first generates an abstract syntax tree with its own parser.{{Cite web|last=Verwaest|first=Toon|date=25 March 2019|title=Blazingly fast parsing, part 1: optimizing the scanner · V8|url=https://v8.dev/blog/scanner|url-status=live|archive-url=https://web.archive.org/web/20210421221018/https://v8.dev/blog/scanner|archive-date=21 April 2021|access-date=1 June 2021|website=v8.dev}} Then, Ignition generates bytecode from this syntax tree using the internal V8 bytecode format.{{Cite web|url=https://medium.com/dailyjs/understanding-v8s-bytecode-317d46c94775|title=Understanding V8's Bytecode|last=Hinkelmann|first=Franziska|date=2017-12-19|website=Medium|language=en|access-date=2019-10-17}} TurboFan compiles this bytecode into machine code. In other words, V8 compiles ECMAScript directly to native machine code using just-in-time compilation before executing it.{{Cite web|title=Firing up the Ignition interpreter · V8|url=https://v8.dev/blog/ignition-interpreter|access-date=2020-09-30|website=v8.dev}} The compiled code is additionally optimized (and re-optimized) dynamically at runtime, based on heuristics of the code's execution profile. Optimization techniques used include inlining, elision of expensive runtime properties, and inline caching. The garbage collector is a generational incremental collector.{{cite web |url=https://blog.chromium.org/2011/11/game-changer-for-interactive.html |title=A game changer for interactive performance |website=blog.chromium.org |date=2011-11-21|access-date=2022-02-06}}
Usage
V8 can compile to x86, ARM or MIPS instruction set architectures in both their 32-bit and 64-bit editions; it has additionally been ported to PowerPC,{{Cite web|url=https://developer.ibm.com/opentech/2015/06/30/ppc-support-for-google-v8-goes-mainstream/|title=PPC support for Google V8 goes mainstream|date=June 30, 2015|archive-url=https://web.archive.org/web/20150912183958/https://developer.ibm.com/opentech/2015/06/30/ppc-support-for-google-v8-goes-mainstream/|archive-date=September 12, 2015|url-status=dead}}{{Cite web|url=https://github.com/ibmruntimes/v8ppc|title=GitHub - ibmruntimes/v8ppc: Port of Google V8 javascript engine to PowerPC®.|date=April 21, 2019|via=GitHub}} and to IBM ESA/390 and z/Architecture,{{Cite web|url=https://github.com/ibmruntimes/v8z|title=Port of Google V8 JavaScript engine to z/OS. The Linux on Z port is maintained in the community: ibmruntimes/v8z|date=April 2, 2019|via=GitHub}} for use in servers.{{cite web |url=http://v8.googlecode.com/svn/trunk/ChangeLog |title=V8 Changelog v3.8.2 |access-date=23 October 2012 |archive-url=https://web.archive.org/web/20121022062411/http://v8.googlecode.com/svn/trunk/ChangeLog |archive-date=22 October 2012 |url-status=dead }}
V8 can be used in a browser or integrated into independent projects. V8 is used in the following software:
- Chromium-based web browsers - Google Chrome, Brave, Opera, Vivaldi and Microsoft Edge.
- Cloud-based environments, like Google Apps Script{{Cite web |title=V8 Runtime Overview {{!}} Apps Script |url=https://developers.google.com/apps-script/guides/v8-runtime |access-date=2025-01-26 |website=Google for Developers |language=en}}
- Couchbase database server
- Deno runtime environment{{Cite web|url=https://github.com/denoland/deno|title=A secure JavaScript/TypeScript runtime built with V8, Rust, and Tokio: denoland/deno|date=July 8, 2019|via=GitHub}}
- Electron desktop application framework, used by the Atom and Visual Studio Code text editors
- MarkLogic database server
- NativeScript mobile application framework{{Cite web|url=https://docs.nativescript.org/core-concepts/android-runtime/overview|title=Overview - NativeScript Docs|website=docs.nativescript.org}}
- Node.js runtime environment{{cite web|url=http://mashable.com/2011/03/10/node-js/|title=Why Everyone Is Talking About Node|author=Jolie O'Dell|date=March 10, 2011|publisher=Mashable}}
See also
- Blink, the Chromium browser engine
{{Portal|Free and open-source software|Internet}}
References
{{Reflist|30em}}
External links
{{Commons category|V8 (JavaScript engine)}}
- {{Official website}}
{{ECMAScript}}
{{Google FOSS}}
{{NodeJs}}
Category:Free and open source interpreters