Skip to content
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

Startup snapshots #1372

Open
HalidOdat opened this issue Jun 29, 2021 · 5 comments · May be fixed by #3041
Open

Startup snapshots #1372

HalidOdat opened this issue Jun 29, 2021 · 5 comments · May be fixed by #3041
Assignees
Labels
E-Hard Hard difficulty problem execution Issues or PRs related to code execution performance Performance related changes and issues

Comments

@HalidOdat
Copy link
Member

Because JavaScript describes so many objects creating them on every Context creation takes some time. But with snapshots we only do it once then we serialize them into a snapshot binary file and all other Context creation just deserializes this binary snapshot file.

V8 uses snapshots to speed up context creation

This will probably require a lot of changes maybe we will need to write our own garbage collector for easier serialization and deserialization.

@HalidOdat HalidOdat added performance Performance related changes and issues execution Issues or PRs related to code execution E-Hard Hard difficulty problem labels Jun 29, 2021
@playXE
Copy link

playXE commented Jul 7, 2021

Starlight implements them almost like in V8 and Boa for sure will need custom GC for this plus a lot of unsafe code. Custom GC is required because for serialization and deserialization how objects are allocated does matter plus all the GC objects need to implement some trait for deser/ser, in Starlight there is a base trait for all GCed objects: GcCell and GcCell requires impl of Serializable and Deserializable. There is also a large array that contains all the native functions or other data exposed to JS VM: jsrt.rs + additional array stored in VM instance so serializer and deserializer know where to get external references.

Serialization and deserialization impl is there:
https://github.com/Starlight-JS/starlight/tree/dev/crates/starlight/src/gc/snapshot

@HalidOdat
Copy link
Member Author

Yeah we need a new GC, rust-gc makes somethings really awkward, also there is not much control (like changing the threshold, or changing when we want collect).

@playXE
Copy link

playXE commented Jul 7, 2021

For me main problem with all the GC crates in Rust is not only the control but how slow and memory inefficient they are. rust-gc if I understand correctly uses reference counting to handle root references which is very slow while other JS engines: V8,JSC and now Starlight just use conservative stack scanning to find roots. There's also alternative like in SpiderMonkey to use shadow stack and Starlight also implements it but its impl is very unsafe and I am not sure if it is possible to implement in safe rust...

@HalidOdat
Copy link
Member Author

HalidOdat commented Jul 7, 2021

Does V8 use conservative stack scanning? I thought it managed roots through scopes (HandleScope) when a scope is destroyed, it's handles are available for collection. since HandleScope keeps track of handles, Handles are copyable.

Matching this in rust would allow us to use lifetimes with scopes and handles, so we could make them more safe.

@playXE
Copy link

playXE commented Jul 7, 2021

They did use handles and scopes but now these are just no-op IIRC. They now use the same GC as Blink does: Oilpan GC. It is mostly precise.

https://v8.dev/blog/high-performance-cpp-gc

@HalidOdat HalidOdat linked a pull request Jun 15, 2023 that will close this issue
6 tasks
@HalidOdat HalidOdat self-assigned this Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-Hard Hard difficulty problem execution Issues or PRs related to code execution performance Performance related changes and issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants