-
Notifications
You must be signed in to change notification settings - Fork 96
Making it possible to use V8 snapshots #21
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
Conversation
Odd, it's failing on Linux
|
@ignisf : dangit :( seems it failed on Travis too (for Linux as well). How did you get that error message? I don't see that in Travis? Trying on an Ubuntu VM. |
I'm no C++ programmer, but keep in mind that by default V8 on linux uses external snapshot data. We've worked around this issue by adding this flag to the V8 build process: https://github.com/cowboyd/libv8/blob/master/ext/libv8/builder.rb#L29-L30 That's about the only thing different I can think of between osx and linux. It could be something completely different. |
Relevant discussion: rubyjs/libv8#178 (comment) |
ran |
Hmm, I'm getting an |
@ignisf : thanks for all that, looking into it shortly :) |
Ok, I think I'm onto something here. I tried this https://developers.google.com/v8/get_started#run-the-example example on my box, getting this:
|
Copying those two files to the local directory allowed me to run the hello world. Here's a branch of libv8 for you to test with: https://github.com/cowboyd/libv8/commits/external-snapshot |
rofl |
@ignisf : thanks a lot for your help, much appreciated. Testing your libv8 branch :) |
np, hopefully you can get to the bottom of this |
just one more thing before I call it a night -- help me grasp the impact of this issue. Am I correct to think that the so called snapshot's purpose is to speed up context creation. And significant performance improvement is expected to be observed in cases which require the creation of many contexts? |
@ignisf : exactly. Our use case is: we have a base context that we could re-use across requests to do server-side pre-rendering. This would allow caching it once and for all |
And I didn't come up with the name "snapshot", V8 did ;-) http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html |
7f26c02
to
1b4ed72
Compare
Thanks! |
6f9af1e
to
1739ffc
Compare
With proper unit tests
@ignisf : fixed, was just me being dumb and having done too little C++ recently :-/ Thanks for your help though! |
A couple of questions:
Is
leaking a StartupData object somehow? |
@SamSaffron : thanks for your review.
|
@SamSaffron : snapshots warm up added (edeaa9d) |
StartupData warm_startup_data = V8::WarmUpSnapshotDataBlob(cold_startup_data, RSTRING_PTR(str)); | ||
|
||
if (warm_startup_data.data == NULL && warm_startup_data.raw_size == 0) { | ||
rb_raise(rb_eSnapshotError, "Could not warp up snapshot, most likely the source is incorrect"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo? Or am I missing the definition of the awesome sounding term "warping up"? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, thanks, fixing ;)
Which maps to V8's `V8::WarmUpSnapshotDataBlob` (see http://v8.paulfryzel.com/docs/master/classv8_1_1_v8.html#abee465cc67755cfaacf0297c3093fb47) Added unit tests on it.
Just a quick note on WarmUpSnapshotDataBlob, it appears to be mostly just to allow you to call functions to get them to compile (as noted in the comments of the function https://github.com/v8/v8/blob/master/src/api.cc#L520) This is because functions are lazily compiled (electron/electron#169 (comment)), the solution in that thread from the creator of snapshots was just to call the functions but wrap them in try/catch to force them to compile. WarmUpSnapshotDataBlob just seems to be a more formal way to solve that particular issue. |
OK I will merge this in, @wk8 since we are getting all fancy here one area that is very weak atm is memory management and visibility, I would love to get some stuff in here. at a minimum visibility on what is currently in use by v8, but more predictable v8 disposal is also quite important (and especially for the snapshot usage, cause you want to dispose the v8 resources asap once you are done) |
Thanks for merging! |
With proper unit tests