V8 is a JavaScript
and WebAssembly
engine developed by Google for its Chrome browser.
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
.
V8是由Google为其Chrome浏览器开发的
JavaScript
和WebAssembly
引擎。
V8是开源软件,属于
Chromium项目
的一部分,并且在非浏览器上下文中
单独使用,特别是在Node.js运行时系统
中。
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 for the powerful car engine
.
For several years, Chrome was faster than other browsers at executing JavaScript.
The V8 assembler is based on the Strongtalk assembler
.
On 7 December 2010, a new compiling infrastructure
named Crankshaft
was released, with speed improvements.
Google为其Chrome浏览器创建了V8,两者最初都是在2008年发布的。
V8的首席开发者是
Lars Bak
,它的命名取自强大的汽车引擎
。
在几年的时间里,Chrome在执行JavaScript方面比其他浏览器更快。
V8的汇编器基于
Strongtalk汇编器
。
在2010年12月7日,发布了一个名为
Crankshaft
的新的编译基础设施
,获得了速度上的改进。
In version 41 of Chrome in 2015, project TurboFan
was added to provide more performance improvements with previously challenging workloads such as asm.js
.
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
.
在2015年Chrome的41版本中,项目
TurboFan
被添加,以提供更多性能改进,先前具有挑战性的工作负载,例如asm.js
。
V8的许多开发受到了
Sun Microsystems
开发的Java HotSpot虚拟机
的强烈启发,更新的执行流水线
与HotSpot
的非常相似。
Support for the new WebAssembly language began in 2015.
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
.
对新的WebAssembly语言的支持始于2015年。
2016年,向V8添加了
Ignition解释器
,旨在减少与TurboFan
和Crankshaft
相比在小内存Android手机上的
内存
使用。
Ignition
is a register based machine and shares a similar (albeit
not the exact same) design to the templating interpreter utilized by HotSpot
.
Ignition
是一个基于寄存器的机器,与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.
从
V8版本5.9
开始,Full-codegen
(早期基线编译器)和Crankshaft
不再用于V8的JavaScript执行,因为团队认为它们无法再跟上新的JavaScript语言特性和这些特性所需的优化
。
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
.
在2021年,随着
SparkPlug
编译器的发布,引入了一套新的分层编译流程
,它在V8内部补充了现有的TurboFan编译器
,直接与HotSpot使用的基于性能分析的C1编译器
并行。
到了2023年,添加了基于
SSA
的Maglev
编译器,比Sparkplug
慢10倍但比TurboFan
快10倍,弥合了
对不够“热”以在
TurboFan进行优化的
频率较低的循环而言的
Sparkplug和
TurboFan之间的差距,这是
大多数Web应用的情况,它们花费的时间与
浏览器交互要比在
JavaScript执行上花费的时间更多。
Design
V8 first generates an abstract syntax tree with its own parser.
Then, Ignition
generates bytecode from this syntax tree
using the internal V8 bytecode format.
TurboFan
compiles this bytecode into machine code.
V8首先使用自己的解析器生成抽象语法树。
然后,
Ignition
使用内部V8字节码格式从这棵语法树
生成字节码。
TurboFan
将这些字节码编译成机器码。
In other words, V8 compiles ECMAScript directly to native machine code using just-in-time compilation before executing it.
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.
换句话说,V8在执行代码之前直接将ECMAScript编译成本地机器码使用即时编译。
编译后的代码在运行时动态进行附加
优化
(和再优化),基于代码的执行样本
的启发式。
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, and to IBM ESA/390 and z/Architecture, for use in servers.
V8 can be used in a browser or integrated into independent projects.
V8可以将代码编译成x86、ARM或MIPS 指令集体系结构,包括它们的32位和64位版本;
此外,V8还被移植到PowerPC,以及用于服务器的IBM ESA/390和z/Architecture。
V8可以在浏览器中使用,也可以集成到独立项目中。
V8 is used in the following software:
- Chromium-based web browsers - Google Chrome, Brave, Opera, Vivaldi and Microsoft Edge.
- Firefox - parts of V8 ported to the browser for regular expressions parsing
- Couchbase database server
- Deno runtime environment
- Electron desktop application framework, used by the Atom and Visual Studio Code text editors
- MarkLogic database server
- NativeScript mobile application framework
- Node.js runtime environment
- Qt Quick runtime environment
V8被用在以下软件中:
- 基于Chromium的网络浏览器 - Google Chrome、Brave、Opera、Vivaldi和Microsoft Edge。
- Firefox - 将部分V8移植到浏览器用于正则表达式解析。
- Couchbase 数据库服务器。
- Deno 运行时环境。
- Electron 桌面应用程序框架,被Atom和Visual Studio Code文本编辑器使用。
- MarkLogic 数据库服务器。
- NativeScript 移动应用框架。
- Node.js 运行时环境。
- Qt Quick 运行时环境。