Skip to content

polyfill: don't compile js on each env start #319

Open
@krichprollsch

Description

@krichprollsch

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.
    ⚠️ 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.


lightpanda-io/zig-js-runtime#263 and lightpanda-io/zig-v8-fork#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions