-
Notifications
You must be signed in to change notification settings - Fork 280
Provides an PoC of using V8 snapshots #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
@krichprollsch, to pass the build and tests, need to build with PR in v8 repo |
|
@mrdimidium,
Do you know if the data is independent from the platform? Could we generate the blob in a file and commit it along the project? Regarding the loading strategy, what about changing the polyfill to be independent from any global object, and only run a small JS when need to create what we need with global objects? I didn't look at the JS code for now, so idk if it's hard to do, but it could worth the try. WDYT? |
|
@krichprollsch, it's not portable across platforms, but it can be generated during the build. For example, Chromium builds the snapshot in GN and packages it into an I was thinking about changing the JS, but I couldn't immediately figure out how to handle the "something in the window was accessed" event before the window actually appears. Maybe something with globalThis? It will also be slower. If we take a snapshot after the JS has executed, we'll get an already initialized window in the snapshot. If we use JS wrappers, it will need to be executed at runtime on the page. |
|
Got it. I'm not sure about the good balance here. I'm afraid we will have to generate the snapshot too often according the way we are creating js env & globals right now. But in the other hand that could force us to refacto for a better way. |
|
Thinking a bit more about that, I'm not sure it worth it, I'm afraid we will have to generate the snapshot at the same moment we currently inject the polyfill. So there will be no gain at all. |
|
I think this could work if the global API preparation were separated from the page. In that case, a snapshot with the WebAPI (including polyfills) could be prepared in advance. This should be done once during the build and completely removed from runtime. But it seems like this would require significant refactoring. |
|
I think I will take a look a the polyfill first to see if we can extract the global deps first. |
|
I tried the branch locally (ubuntu x86_64), the webcomponent test is working correctly. But I have a crash when running the whole test suite 🤔 |
|
Interesting, It's an debug assert, but I don't see it. @krichprollsch, are you building on a Mac or Linux? |
|
linux, x86_64 (ubuntu 24.04) |
|
Give me some time to figure this out. You can temporarily disable dcheck in args.gn. |
|
Regarding decoupling the polyfill from window, this experiment is working: 5a1564d
|
Provides a proof of concept on how to use snapshots for #1176. Depends on PR in v8 repository.: lightpanda-io/zig-v8-fork#110
As stated in the documentation, snapshots are serialized state of the V8 heap. We simply execute JavaScript code and save the snapshot (it can be saved to disk if desired). In the PR above, you can see how a snapshot is created at browser startup, which provides the
LightpandaSnapshotPoCfunction, later accessible in tests.Since the polyfill is still JavaScript code, it can only be executed and serialized along with the initialization of window* and other global objects, like this:
Currently, this isn't very convenient to do in code, as the snapshot must be ready before creating the Env. I'd like to discuss the implementation in advance:
@krichprollsch, wdyt?