browser
browser copied to clipboard
polyfill: don't compile js on each env start
Currently, when we load polyfills, we always compile and run javascript scripts. It would be better to compile once and run multiple times.
An idea would be:
-
create a
ScriptCompiler::Source
[0] -
replace the usage of
ScriptCompiler::Compile
[1] withScriptCompiler::CompileUnboundScript
[2]. Use the createdScriptCompiler::Source
. :warning: The doc is wrong, the func needs a context (see https://chromium.googlesource.com/v8/v8.git/+/refs/heads/main/src/api/api.cc#2582 and https://groups.google.com/u/1/g/v8-users/c/btTLjLN9uZg/m/v6cZ64RKBQAJ -
call
ScriptCompiler::CreateCodeCache
[3] to save aCachedDate
. -
call
UnboundScript::BindToCurrentContext
[4] to bind with the current context an retrieve aScript
. -
run the script [5]
-
The next start, pass the saved
CachedData
when creating theScriptCompiler::Source
[0] -
repeat the following steps.
https://github.com/lightpanda-io/zig-js-runtime/pull/263 and https://github.com/lightpanda-io/zig-v8-fork/pull/32 expose the UnboundScript
functions but CachedData
funcs are missing. A question is: how to encapsulate and expose v8 CachedData
logic in zig-js-runtime?