时隔一年,Node.js 12 如约而至,正式发布第一个 Current 版本。javascript
该版本带来了诸如:html
原文地址:https://medium.com/@nodejs/introducing-node-js-12-76c41a1b3f3fjava
相关文章:Node.js 10 值得关注的新特性node
若是你不了解 Node.js 的 Long Term Support 发布策略的话,必定要看看 https://github.com/nodejs/Release 。git
就目前而言,Node.js 6.x 和 8.x 将在 2019 年底结束 LTS 的支持,你们尽快升级到 10.x 吧。github
$ nvs add node/12 $ nvs use 12 $ node -v v12.0.0
具体参考这篇文章:科普文:使用 nvs 管理本地 Node.js 版本npm
本次版本更新,也带来了好几个不错的特性:api
同时,跑了下咱们 Egg 的一些内部测试,发现序列化有 10~20% 的性能提高,恐怖如斯!缓存
另,奇丑无比的 Private Class Fields 也能用了:安全
class IncreasingCounter { #count = 0; get value() { console.log('Getting the current value!'); return this.#count; } increment() { this.#count++; } }
默认的 HTTP 解析器切换为 llhttp ,性能提高恐怖如斯:
经过 v8 code cache 的支持,在构建时提早为内置库生成代码缓存,从而提高 30% 的启动耗时。
同时,经过重用主进程缓存,Workers Threads 的启动速度提高了 60% 。
在 10.x 已经引入的 Workers Threads 特性,在 12.x 里面默认启用,无需使用 --experimental-worker
开启。同时基于上一条的介绍,启动的速度也获得大幅提高。
相关介绍:https://medium.com/@Trott/using-worker-threads-in-node-js-80494136dbb6
提供了新的实验性功能『诊断报告』,一个很是有用的特性。
可用于帮助分析诸如:崩溃,性能问题,内存泄漏,高 CPU 占用等等问题。详见 这篇文章。
之前咱们分析问题的时候,须要手动安装对应的类库或者使用 AliNode。
在 12.x 里面内置了该功能,详见:
同时,因为上述提到的 V8 升级,如今能够按照可用内存动态调整堆大小了。
ES6 模块仍然还在实验阶段,不过有了新的方式,具体参见这篇文章。
GCC 6
和 glibc 2.17
,对应的操做系统 Win7 和 macOS 10,详细参见这篇文章。不过目前 node-gyp 的一些原生模块会编译失败:
nunjucks@3.2.0 › chokidar@2.1.5 › fsevents@^1.2.7 optional error: Error: Run "sh -c node install" error, exit code 1 at ChildProcess.<anonymous> (/Users/tz/.npm-global/lib/node_modules/tnpm/node_modules/_runscript@1.3.0@runscript/index.js:74:21) at ChildProcess.emit (events.js:196:13) at maybeClose (internal/child_process.js:1000:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:267:5)
如有侵权及时联系。