NodeJS 中是否有任何 JIT 预缓存支持? [英] Is there any JIT pre-caching support in NodeJS?

查看:35
本文介绍了NodeJS 中是否有任何 JIT 预缓存支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个相当大且性能密集的 nodejs 程序来生成 CJK 字体的提示数据 (sfdhanautohint),为了更好的依赖关系跟踪,我不得不从 makefile 中调用 nodejs 程序数万次 像这样.

I am using a rather large and performance-intensive nodejs program to generate hinting data for CJK fonts (sfdhanautohint), and for some better dependency tracking I had to end up calling the nodejs program tens of thousands of times from a makefile like this.

这立即让我担心这样做实际上会在启动和预热 JIT 引擎时产生大量开销,因此我决定为 nodejs 找到类似 ngen.exe 的东西.看起来 V8 已经对代码缓存有一些支持,但是有我可以做些什么来在 NodeJS 中使用它?

This immediately brought me to the concern that doing such is actually putting a lot of overhead in starting and pre-heating the JIT engine, so I decided to find something like ngen.exe for nodejs. It appears that V8 already has some support for code caching, but is there anything I can do to use it in NodeJS?

正在搜索 NodeJS 的 GitHub 存储库中的 kProduceCodeCache 不会返回任何非捆绑的 v8 结果.也许是时候进行功能请求...

推荐答案

是的,这会自动发生.Node 5.7.0+ 会在您第一次运行代码时自动预缓存(为您的源代码预热 JIT 引擎)(自 PR #4845/2016 年 1 月在这里:https://github.com/nodejs/node/pull/4845).

Yes, this happens automatically. Node 5.7.0+ automatically pre-caches (pre-heats the JIT engine for your source) the first time you run your code (since PR #4845 / January 2016 here: https://github.com/nodejs/node/pull/4845).

需要注意的是,您甚至可以预热预热(在您的代码甚至在机器上运行之前,您可以预先缓存您的代码并告诉 Node 加载它).

It's important to note you can even pre-heat the pre-heat (before your code is ever even run on a machine, you can pre-cache your code and tell Node to load it).

Andres Suarez,一位从事 Yarn、Atom 和 Babel 的 Facebook 开发人员创建了 v8-compile-缓存,这是一个很小的模块,它会JIT你的代码和require()s,并将你的Node缓存保存到你的$TMP文件夹中,如果找到的话就使用它.查看源代码,了解它是如何满足其他需求的.

Andres Suarez, a Facebook developer who works on Yarn, Atom and Babel created v8-compile-cache, which is a tiny little module that will JIT your code and require()s, and save your Node cache into your $TMP folder, and then use it if it's found. Check out the source for how it's done to suit other needs.

如果您愿意,可以在启动时运行一些检查,如果机器架构在您的缓存文件集中,只需加载缓存文件,而不是让 Node JIT 一切.对于具有大量需求的现实世界大型项目,这可以将您的加载时间减少一半或更多,并且可以在第一次运行时完成

You can, if you'd like, have a little check that runs on start, and if the machine architecture is in your set of cache files, just load the cached files instead of letting Node JIT everything. This can cut your load time in half or more for a real-world large project with tons of requires, and it can do it on the very first run

适合加速容器并使它们低于 500 毫秒的微服务"启动时间.

Good for speeding up containers and getting them under that 500ms "microservice" boot time.

需要注意的是:

  1. 缓存是二进制文件;它们包含机器可执行代码.它们不是您的原始 JS 代码.
  2. 对于您打算在其上运行的每个目标 CPU(IA-32、IA-64、ARM 等),节点缓​​存二进制文件是不同的.如果您想为您的用户预缓存预缓存,您必须为您想要支持的每个目标架构制定缓存目标.
  3. 享受可笑的速度提升:)

这篇关于NodeJS 中是否有任何 JIT 预缓存支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆