What optimizations do modern JavaScript engines perform?

后端 未结 2 1770
一整个雨季
一整个雨季 2021-01-31 21:30

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 har

相关标签:
2条回答
  • 2021-01-31 21:36

    I found an additional resource:

    • What does V8 do with that loop?
    0 讨论(0)
  • 2021-01-31 21:56

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

    • 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.

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

    • Bytecode optimizations
    • Polymorphic inline cache (like V8)
    • Context threaded JIT (introduction of native machine code generation, like V8)
    • Regular expression JIT

    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.

    0 讨论(0)
提交回复
热议问题