Code Monkey home page Code Monkey logo

Comments (8)

laverdet avatar laverdet commented on July 30, 2024 1

I think you're expecting too much from snapshots. Snapshots in v8 are very fragile and based on my experience I believe they are intended to cache only parsed/compiled JS code not to cache a "warmed up" application with lots of state on the heap.

from isolated-vm.

laverdet avatar laverdet commented on July 30, 2024

I don't think this is going to be possible. The API for creating snapshots in v8 is pretty locked down with lots of restrictions. Basically, the way you go about creating a snapshot is very different from the way you go about using an isolate for general purposes. You can put as many scripts as you want into the snapshot initialization though, that gives you lots of freedom for what goes into your snapshot.

from isolated-vm.

RiftLurker avatar RiftLurker commented on July 30, 2024

That's unfortunate, I'll see if I can get something done with the current snapshot feature, but I don't think this is going to work out the way I want to.

Thanks for the reply anyways.

from isolated-vm.

lev-kazakov avatar lev-kazakov commented on July 30, 2024

@laverdet we'd also be grateful for this feature. is there any chance this will be implemented? thx.

from isolated-vm.

laverdet avatar laverdet commented on July 30, 2024

@lev-kazakov it's impossible. The snapshot feature is intended to just cache library code.

from isolated-vm.

lev-kazakov avatar lev-kazakov commented on July 30, 2024

@laverdet thx, another question if i may:
will it be possible for ivm.Isolate.createSnapshot() to receive a third parameter, say "global"/"bindings"/"polyfills" that will receive a set of transferrables/references, and make them available from the global scope of the isolate?
e.g if i do something like this:

const snapshot = ivm.Isolate.createSnapshot([{code: `log('crap')`}], undefined, {
  log: new ivm.Reference(function(...args) {
    console.log(...args);
  }
})

then log would be available to any script on the scripts array.

if this is realistic, i'll open a new issue of course :)

from isolated-vm.

laverdet avatar laverdet commented on July 30, 2024

@lev-kazakov that's not possible either because the 3rd parameter in your example would only last as long as the nodejs process is alive. You can save a snapshot to disk and load it into any number of new nodejs processes, and in those processes your log function wouldn't exist anymore.

from isolated-vm.

lev-kazakov avatar lev-kazakov commented on July 30, 2024

@laverdet maybe this can be done by providing an additional polyfills option to the options object in new ivm.Isolate(options).
it will be the responsibility of the user to creating an isolate from snapshot to provide the same polyfills (by name) used to create the snapshot.

from isolated-vm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.