V8 released 8.0 version, which in addition to fix some bug, no doubt has brought improved performance. Currently is a preview, the official version will be after a few weeks with Chrome 80 Stable released together.
Performance Improvements
Take a look at performance improvements , including reducing memory footprint and faster:
Pointer compression
V8 heap all things contain the entire project, such as floating point values, strings of characters, compiled code and tag values (tagged values), tag represents the stack pointer points to V8 or a small integer, the development team found that these markers values occupy the heap most of the space.
Tag value as large as the system pointer, for 32-bit architecture, the 32-bit width thereof, in the 64-bit architecture, was 64. When the 32-bit and 64-bit versions are compared, the heap memory used for each label value is doubled.
This release is reduced by a method that a memory: a pointer compression. Because high can be synthesized from the low and need to be stored only save low to heap memory resources, after testing, saving an average of 40% of heap memory.
Usually while reducing memory, it will sacrifice speed performance, but after this improvement, V8 and garbage collectors are able to see the real website to enhance performance.
Built-in high-order optimization program
This version eliminates a restriction TurboFan optimize the pipeline, which is optimized for higher-order limitations prevent the built-in functions.
const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt);
charCodeAt(string, 8);
charCodeAt TurboFan call is completely opaque, leading to a general call generates user-defined functions. This change can now be identified is in fact built String.prototype.charCodeAt function call, which can trigger all further optimized to improve inventory TurboFan call to the built-in functions, and then get the same performance with the following code:
string.charCodeAt(8);
JavaScript
JavaScript features that there are variations, brings two new features:
Optional Chaining
When writing property access chain, developers often need to check if the middle value is empty (null or undefined), this could write very lengthy explicit error checking chains.
// Error prone-version, could throw.
const nameLength = db.user.name.length;
// Less error-prone, but harder to read.
let nameLength;
if (db && db.user && db.user.name)
nameLength = db.user.name.length;
Optional Chaining(?.)使开发者可以编写更可靠的属性访问链,以检查中间值是否为空。如果中间值是空值,则整个表达式的计算结果为 undefined。
// Still checks for errors and is much more readable.
const nameLength = db?.user?.name?.length;
同时,除了静态属性访问之外,Optional Chaining 还支持动态属性访问和调用。
null 合并(Nullish Coalescing)
另一个与 Optional Chaining 很接近的特性是 null 判断合并(Nullish Coalescing),由特定的 Nullish Coalescing 操作符 ?? 启用,它是一个新的短路二元运算符。
现在有时会使用逻辑 || 运算符处理默认值,例如:
function Component(props) {
const enable = props.enabled || true;
// …
}
运算 a || b,当 a 为非真时结果为 b,如果 props.enabled 本身显式设置为“false”,那么这样的运算还是会得到第二个运算数“true”,也就是 enable = true。
现在使用 null 合并运算符 ??,当 a 为空,也就是 null 或者 undefined 时,a ?? b 的运算结果为 b,否则为 a,这样的默认值处理行为才是符合逻辑的,弥补了前边讲到的问题。
function Component(props) {
const enable = props.enabled ?? true;
// …
}
同时,null 合并运算符和 Optional Chaining 是辅助功能,可以很好地协同工作。它们可以进一步处理上述示例中没有任何 props 参数传入的情况。
function Component(props) {
const enable = props?.enabled ?? true;
// …
}
此外,API 有一些变化,可以通过以下方式查看:
git log branch-heads/7.9..branch-heads/8.0 include/v8.h
更新说明: