什么做优化现代JavaScript引擎执行?引擎、现代、JavaScript

2023-09-11 00:46:14 作者:爱情没有办法弄虚作假ぅ

目前,大部分主流浏览器都开始整合优化的JIT编译器,以他们的JavaScript跨preters /虚拟机。这是对大家都有好处。现在,我会pssed确切地知道哪些优化他们执行以及如何最好地利用这些优势硬$ P $。什么是每一个主要的JavaScript引擎上的优化参考?

By now, most mainstream browsers have started integrating optimizing JIT compilers to their JavaScript interpreters/virtual machines. That's good for everyone. Now, I'd be hard-pressed to know exactly which optimizations they do perform and how to best take advantage of them. What are references on optimizations in each of the major JavaScript engines?

背景:

我工作的一个编译器生成JavaScript从一个更高的层次和放大器;更安全的语言(无耻插头:这就是所谓的 OPA ,它是非常酷),并给出了应用程序,我产生了大小,我想我的JavaScript code是一样快,内存效率越好。我可以处理高层次的优化,但我需要知道更多的运行时转换执行哪些,这样才能知道哪个低级别的code会产生最好的结果。

I'm working on a compiler that generates JavaScript from a higher-level & safer language (shameless plug: it's called OPA and it's very cool) and, given the size of applications I'm generating, I'd like my JavaScript code to be as fast and as memory-efficient as possible. I can handle high-level optimizations, but I need to know more about which runtime transformations are performed, so as to know which low-level code will produce best results.

一个例子,从我的脑海顶:我编译会很快集成懒惰支持的语言。不要JIT发动机懒函数定义的行为呢?

One example, from the top of my mind: the language I'm compiling will soon integrate support for laziness. Do JIT engines behave well with lazy function definitions?

推荐答案

这系列文章讨论V8的最佳化。总结:

This article series discusses the optimisations of V8. In summary:

在它产生的本机code - 不是字节code(的 V8设计元素) precise 垃圾收集(维基百科) 内联缓存称为方法(维基百科) 保存类过渡信息,使具有相同属性的对象组合在一起(的 V8设计元素) It generates native machine code - not bytecode (V8 Design Elements) Precise garbage collection (Wikipedia) Inline caching of called methods (Wikipedia) Storing class transition information so that objects with the same properties are grouped together (V8 Design Elements)

前两点可能不会帮你了这种情况。第三个可能显示洞察把事情缓存起来。最后一个可以帮助你创建具有相同属性的对象,所以它们使用相同的隐藏的类。

The first two points might not help you very much in this situation. The third might show insight into getting things cached together. The last might help you create objects with same properties so they use the same hidden classes.

这个博客帖子讨论一些的SquirrelFish极端的最佳化的:

This blog post discusses some of the optimisations of SquirrelFish Extreme:

字节code优化 在多形内联高速缓存(如V8) 在上下文线程JIT(介绍本机code一代,像V8) 正前pression JIT

的TraceMonkey是通过跟踪优化。我不知道很多关于它,但它看起来像它检测到某些变量的类型的热code 的(在循环中经常code运行),并创建优化的$ C基于什么该变量的类型是$ C。如果变量类型改变时,它必须重新编译code - 基于过这个,我说你应该远离改变一个循环内的变量的类型

TraceMonkey is optimised via tracing. I don't know much about it but it looks like it detects the type of a variable in some "hot code" (code run in loops often) and creates optimised code based on what the type of that variable is. If the type of the variable changes, it must recompile the code - based off of this, I'd say you should stay away from changing the type of a variable within a loop.