Size limitation on the snapshot file?

117 views
Skip to first unread message

Zhao Cheng

unread,
Feb 5, 2014, 10:30:28 PM2/5/14
to v8-u...@googlegroups.com
Hi v8-users,

I'm working on a desktop application which is very sensible to the startup time, I saw that V8's snapshot feature is exactly for this purpose, so I patched V8 to make it accept external snapshot files.

For small snapshot files this worked perfectly, but after I tried with large extra js files (like jquery), the v8::Initialize would fail with following stack trace:
 
Current executable set to './out/Release/v8_shell' (x86_64).
(lldb) run
Process 22132 launched: './out/Release/v8_shell' (x86_64)
Process 22132 stopped
* thread #1: tid = 0x2f53c, 0x00000001000876fd v8_shell`v8::internal::Heap::ClearJSFunctionResultCaches() [inlined] v8::internal::FixedArray::get(context=0x0000000000000000, index=56) at objects-inl.h:1956, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x1cf)
    frame #0: 0x00000001000876fd v8_shell`v8::internal::Heap::ClearJSFunctionResultCaches() [inlined] v8::internal::FixedArray::get(context=0x0000000000000000, index=56) at objects-inl.h:1956
   1953
   1954 Object* FixedArray::get(int index) {
   1955  ASSERT(index >= 0 && index < this->length());
-> 1956  return READ_FIELD(this, kHeaderSize + index * kPointerSize);
   1957 }
   1958
   1959
(lldb) bt
* thread #1: tid = 0x2f53c, 0x00000001000876fd v8_shell`v8::internal::Heap::ClearJSFunctionResultCaches() [inlined] v8::internal::FixedArray::get(context=0x0000000000000000, index=56) at objects-inl.h:1956, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x1cf)
    frame #0: 0x00000001000876fd v8_shell`v8::internal::Heap::ClearJSFunctionResultCaches() [inlined] v8::internal::FixedArray::get(context=0x0000000000000000, index=56) at objects-inl.h:1956
    frame #1: 0x00000001000876fd v8_shell`v8::internal::Heap::ClearJSFunctionResultCaches(this=<unavailable>) + 93 at heap.cc:850
    frame #2: 0x0000000100088e5f v8_shell`v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollector, char const*, char const*) [inlined] v8::internal::Heap::GarbageCollectionPrologue(this=<unavailable>) + 24 at heap.cc:440
    frame #3: 0x0000000100088e47 v8_shell`v8::internal::Heap::CollectGarbage(this=0x0000000101803210, space=<unavailable>, collector=<unavailable>, gc_reason=0x00000001003a1f58, collector_reason=<unavailable>) + 263 at heap.cc:676
    frame #4: 0x0000000100089bad v8_shell`v8::internal::Heap::ReserveSpace(int*, unsigned char**) [inlined] v8::internal::Heap::CollectGarbage(this=0x0000000101803210, gc_reason=<unavailable>) + 109 at heap-inl.h:546
    frame #5: 0x0000000100089b81 v8_shell`v8::internal::Heap::ReserveSpace(int*, unsigned char**) [inlined] v8::internal::AbortIncrementalMarkingAndCollectGarbage(v8::internal::Heap*, v8::internal::AllocationSpace, char const*) + 16 at heap.cc:780
    frame #6: 0x0000000100089b71 v8_shell`v8::internal::Heap::ReserveSpace(this=0x0000000101803210, sizes=0x00007fff5fbff6a0, locations_out=0x00007fff5fbff660) + 49 at heap.cc:809
    frame #7: 0x000000010020a939 v8_shell`v8::internal::Deserializer::Deserialize(this=0x00007fff5fbff648, isolate=0x0000000101803200) + 41 at serialize.cc:815
    frame #8: 0x000000010011ca4a v8_shell`v8::internal::Isolate::Init(this=0x0000000101803200, des=0x00007fff5fbff648) + 2522 at isolate.cc:2260
    frame #9: 0x000000010023125c v8_shell`v8::internal::V8::Initialize(des=<unavailable>) + 124 at v8.cc:78
    frame #10: 0x000000010020d3b0 v8_shell`v8::internal::Snapshot::Initialize(snapshot_file=<unavailable>) + 880 at snapshot-common.cc:152
    frame #11: 0x0000000100009368 v8_shell`v8::V8::Initialize(char const*) [inlined] v8::InitializeHelper(snapshot_file=0x0000000100396e30) + 18 at api.cc:315
    frame #12: 0x0000000100009356 v8_shell`v8::V8::Initialize(snapshot_file=0x0000000100396e30) + 38 at api.cc:5179
    frame #13: 0x0000000100001093 v8_shell`main(argc=1, argv=0x00007fff5fbff810) + 67 at shell.cc:75
    frame #14: 0x0000000100001044 v8_shell`___lldb_unnamed_function1$$v8_shell + 52

As I searched in the mailing list, there seems to be a object space limitation on the snapshot feature, is this true? And is there a way to get round of the size limitation (like changing some predefined constant variable)?

I also notice that ScriptData can be used to precompile script, is the ScriptData serializable so I could write it in a file and the load it in clients' machines? And is there any benchmark on how much time ScriptData could save?

My patch for V8 can be found here, there is nothing special in it and it just made V8 to accept external snapshot file.

Thanks,
Cheng

Ben Noordhuis

unread,
Feb 6, 2014, 5:04:11 PM2/6/14
to v8-u...@googlegroups.com
On Thu, Feb 6, 2014 at 4:30 AM, Zhao Cheng <zcb...@gmail.com> wrote:
> I also notice that ScriptData can be used to precompile script, is the
> ScriptData serializable so I could write it in a file and the load it in
> clients' machines? And is there any benchmark on how much time ScriptData
> could save?

IIRC, the preparser output is basically a dump of the AST. I think it
will work on another machine provided but only if that machine has the
same endianness.

I benchmarked the impact of pre-parsing for node.js about a year ago
where I pre-parsed src/node.js and the stuff in lib/ in the hope of
reducing start-up time but it made no measurable difference.

If memory serves, Vyacheslav Egorov (that's mraleph) mentioned it's
only good for really big scripts, like Emscripten-generated code.

Yi Shen

unread,
Feb 26, 2014, 5:05:40 PM2/26/14
to v8-u...@googlegroups.com
Hi Zhao Cheng,

Have you solved this problem? Could you let me know how you create the snapshot for jquery?

Thanks,
Yi

Cheng Zhao

unread,
Feb 27, 2014, 12:16:22 PM2/27/14
to v8-u...@googlegroups.com
No, it is still unsolved. The snapshot was created with the mksnapshot tool which was created when building V8.

Cheng


--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yong Wang

unread,
Mar 28, 2014, 5:43:29 AM3/28/14
to v8-u...@googlegroups.com
Maybe you should use --extra_code flag to snapshot external js file.

and  how do you handle DOM objects used in jquery?
I don't think mksnapshot can hanlde this case.


在 2014年2月28日星期五UTC+8上午1时16分22秒,Zhao Cheng写道:
Reply all
Reply to author
Forward
0 new messages