Why does v8 saves the source code of native javascript in generated binaries?

前端 未结 2 2029
再見小時候
再見小時候 2021-02-06 12:50

I\'ve been studying the v8 source, particularly at how the \'mksnapshot\' tool includes a compiled image of the native javascript files(runtime.js, json.js...) in the v8 binarie

相关标签:
2条回答
  • 2021-02-06 13:14

    Actually snapshot does not include all builtins in the compiled form.

    V8 in general prefers lazy compilation to save space and time. If you compile things that are not used you waste memory for generated code (and code generated by a non-optimizing compiler is quite "verbose") and time (either on compilation or on deserialization if we are talking about snapshot).

    So everything that it can compile lazily V8 does compile lazily and this includes builtins. Thus snapshot does not actually contain compiled versions for all functions and source is required to compile rest.

    Another thing that becomes possible when source is present is optimization: V8 has to have access to the source to apply its adaptive optimization pipeline.

    0 讨论(0)
  • 2021-02-06 13:17

    Probably because caching the binary is what makes v8 so incredibly fast: It was built to be very fast. So they have taken extreme steps to make it fast. Pre-generated binaries of native code take away the thinking from the client, making it run just that much faster. There are optimizations like this all over v8. :)

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