atom/electron-link

Native functions can be included in the snapshot with newer V8.

Opened this issue · 6 comments

I'm the author and maintainer of V8's custom start-up snapshot. I just came across this project recently. I think you would find this design document very interesting.

A few highlights:

  • FunctionTemplates and ObjectTemplates and their instances can now be serialized, provided that the native function address is provided to v8::SnapshotCreator.
  • FunctionTemplates and ObjectTemplates objects can be extracted from the snapshot, so there is no need to set them up from scratch.
  • Content of internal fields (set by the embedder) in an object can now be serialized/deserializer through user-defined callbacks.
  • Multiple context snapshots per start-up snapshot blob.

Please let me know if you are interested and have questions.

@hashseed We are still using V8 5.6 in Atom and from the blog post it seems that this is available in 5.7. Upgrading to Electron 1.7 would bring V8 up to 5.8

/cc: @as-cii

@hashseed Just got around to reading the blog post. This looks promising, but it's not immediately clear to me how we'd use these native APIs. Currently we just run mksnapshot on our heavily doctored, concatenated script, but it looks like we'd need to write something custom in C++ maybe to register native functions. Also, a lot of those native functions are provided by Blink, Node, etc.

What do you think would be the best general path forward for using these capabilities? The ideal scenario would be to somehow start a normal Atom window and get it to a certain point in its startup cycle, then create a snapshot from there. But it looks like in those APIs you need to create a specific SnapshotCreator object which maintains its own isolate. Could we somehow hack Blink to use a snapshot creator's isolate for a new window so that we could do this? Or assuming that's not possible, what would be your overall strategy for transitioning from the giant electron-link script plus mksnapshot to something wouldn't need to defer?

/cc @as-cii

There's a blog post on this: https://v8project.blogspot.de/2017/05/energizing-atom-with-v8s-custom-start.html

Hi, is this link still available? I clicked it and jump to https://v8.js.cn/blog/custom-startup-snapshots/, this blog looks like outdated.

@hashseed Is there a documentation for including native modules in the snapshot?

There is a v8.dev blog post explaining the high-level concepts, but it's probably best to just look at the test cases, e.g. this one