Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

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

Open
hashseed opened this issue Apr 20, 2017 · 6 comments
Open

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

hashseed opened this issue Apr 20, 2017 · 6 comments

Comments

@hashseed
Copy link

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
Copy link
Author

@Ben3eeE
Copy link

Ben3eeE commented Oct 11, 2017

@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

@nathansobo
Copy link
Contributor

nathansobo commented Nov 12, 2017

@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

@wzt12353202
Copy link

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.

@aminya
Copy link
Contributor

aminya commented Sep 28, 2020

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

@hashseed
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants