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

前端 未结 2 2035
再見小時候
再見小時候 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.

提交回复
热议问题