browser icon indicating copy to clipboard operation
browser copied to clipboard

polyfill: don't compile js on each env start

Open krichprollsch opened this issue 2 months ago • 0 comments

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:

  1. create a ScriptCompiler::Source [0]

  2. replace the usage of ScriptCompiler::Compile [1] with ScriptCompiler::CompileUnboundScript [2]. Use the created ScriptCompiler::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

  3. call ScriptCompiler::CreateCodeCache [3] to save a CachedDate.

  4. call UnboundScript::BindToCurrentContext [4] to bind with the current context an retrieve a Script.

  5. run the script [5]

  6. The next start, pass the saved CachedData when creating the ScriptCompiler::Source [0]

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

krichprollsch avatar Dec 03 '24 16:12 krichprollsch