This project has moved and is read-only. For the latest updates, please go here.

Is there a way to serialize/save a V8Script?

Oct 5, 2013 at 1:39 PM
First off, thank you for the amazing project! It has been an absolute blast to work with.

I know very little about V8, but as I understand, V8Scripts are compiled within the context of an isolate. But is there some way to store these scripts in some sort of byte format so that I can ship them across processes or store them somehow? I would then need a way to re-attach them to a new runtime/engine, which is probably not possible. Thanks!
Oct 5, 2013 at 5:54 PM
Edited Oct 5, 2013 at 5:58 PM
Hi joshrmt, and thanks for your kind words!

The short answer is no, V8 does not support compiled script serialization.

However, V8 does have a "pre-parsing" feature whereby it can scan script code and generate binary data that can be used to speed up the compilation of that same script. Our understanding is that it provides no benefit the first time you compile a script, but it can speed up subsequent recompilation.

The pre-parse data can be stored and shipped across process boundaries. The combination of script code with matching pre-parse data might be close to what you're looking for; a serializable script format that must still be compiled, but compilation should be significantly faster.

We've never experimented with this feature, and we don't know how much of a speed boost it provides, but V8's API appears to support it. It might be interesting to leverage it in ClearScript. We'll definitely take a look. Thank you!

In the meantime, your best option is simply to ship the script code and compile it at the destination.

Oct 5, 2013 at 6:26 PM
Thanks for the quick reply! I noticed that Clearscript is namespaced/licensed as Microsoft. Is this project 'owned'/managed by Microsoft in some way?
Oct 5, 2013 at 8:34 PM
Yes, ClearScript was developed at Microsoft and released on CodePlex in January of this year.