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

Allow loading non-static snapshots #4402

Closed
mraerino opened this issue Mar 16, 2020 · 4 comments · Fixed by #5187
Closed

Allow loading non-static snapshots #4402

mraerino opened this issue Mar 16, 2020 · 4 comments · Fixed by #5187

Comments

@mraerino
Copy link
Contributor

mraerino commented Mar 16, 2020

I'm using deno_core inside my own library.

I would like to be able to load snapshots from binary blobs at runtime.
They could be coming from a local file or the network.
This is currently blocked by the fact that Snapshots need a static lifetime.

In v8::CreateParams.set_snapshot_blob there is a restriction for the lifetime of a snapshot and I imagine that's why a static lifetime was chosen for v8::StartupData:

To avoid unnecessary copies of data, V8 will point directly into the given data blob, so pretty please keep it around until V8 exit.

I think it should be enough to make it live as long as the isolate, right?

From a comment in #4403:

So I'd much rather see a solution where an Isolate can take ownership of a Box<[u8]> that contains the snapshot.

@kitsonk
Copy link
Contributor

kitsonk commented Mar 16, 2020

Makes total sense... Great idea and contribution!

@mathiasrw
Copy link

@mraerino Thank you for the contribution.

Been looking into making a proof of concept for #986 (compile ts code into a single executable binary)

Would love to have a look at how you deal with loading the snapshot. Is your project open on github?

@mraerino
Copy link
Contributor Author

@mathiasrw FTR: I'm not sure if my change will help a lot with that feature.

I don't have a public project using this. We're using Deno internally in a very large project.

The basic usage of this change is like this:

use deno_core::{CoreIsolate, StartupData, Snapshot};

let bytes: Vec<u8> = /* load me from file or somewhere else */;
let boxed = bytes.into_boxed_slice();
let isolate = CoreIsolate::new(StartupData::Snapshot(Snapshot:Boxed(boxed)), false);

@mathiasrw
Copy link

@mraerino Thank you for the input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants