javascript – 节点版本8中Async / Await的性能指南
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 节点版本8中Async / Await的性能指南,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1930字,纯文字阅读大概需要3分钟。
内容图文
async / await可用于节点版本8.代码在nodejs中首次是线性的,本机.那很好.之前很多文章都声称,在v8 javascript引擎中,没有优化try / catch块的功能.现在,async / await需要try / catch块来处理错误.那么,作为开发人员需要做些什么才能保持相同的性能?
解决方法:
try / catch在V8 5.3(Node v7.x及更高版本)的commit 9aac80f中收到了TurboFan优化.这意味着try / catch性能不佳的历史性陈述不再适用.
从V8 blog post开始:
In the past V8’s had difficulties optimizing the kind of language features that are found in ES2015+. For example, it never became feasible to add exception handling (i.e.
try/catch/finally
) support to Crankshaft, V8’s classic optimizing compiler. This meant V8’s ability to optimize an ES6 feature likefor...of
, which essentially has an implicit finally clause, was limited. Crankshaft’s limitations and the overall complexity of adding new language features to full-codegen, V8’s baseline compiler, made it inherently difficult to ensure new ES features were added and optimized in V8 as quickly as they were standardized.Fortunately, Ignition and TurboFan (V8’s new interpreter and compiler pipeline), were designed to support the entire JavaScript language from the beginning, including advanced control flow, exception handling, and most recently
for...of
and destructuring from ES2015. The tight integration of the architecture of Ignition and TurboFan make it possible to quickly add new features and to optimize them fast and incrementally.
异步函数中的try / catch只是对Promise .then和.catch方法的合成糖,因此性能由底层的Promise实现决定. Bluebird claims具有比原生Promise实现更好的性能,因此理论上 – 如果Bluebird声称的是真的 – 通过使用Bluebird的Promise实现覆盖原生Promise实现,您将获得更好的尝试/捕获性能.
例如,在Node:const Promise = require(“bluebird”)或global.Promise = require(“bluebird”)中全局覆盖它.
但请注意,这可能会在未来发生变化,因为最初的Promise实现是在JavaScript中,但最近已在C中重新实现,因为可以在错误#5343中进行跟踪.
内容总结
以上是互联网集市为您收集整理的javascript – 节点版本8中Async / Await的性能指南全部内容,希望文章能够帮你解决javascript – 节点版本8中Async / Await的性能指南所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。