I'm using node and v8 to run a relatively big program on an embedded system. Studies indicate that compiling the user javascript code sometimes take up to 3 seconds, which make for slow startup times of the javascript application.
Is there any way to speed this up? I have been trying to use the ScriptCompiler::CachedData, producing this on first compilation and then saving to disk. But I have been running into problems.
1)
If I use ScriptCompiler::kProduceCodeCache I often get problems when serializing, with a failure in CodeSerializer::SerializeObject that I don't understand:
// The code-caches link to context-specific code objects, which
// the startup and context serializes cannot currently handle.
DCHECK(!heap_object->IsMap() ||
Map::cast(heap_object)->code_cache() ==
heap_object->GetHeap()->empty_fixed_array());
Can anyone explain why I get this? I don't understand the comment.
IF compilation and serializing succeeds I will get a CachedData that I try to save to disk. On subsequent loads of the process it seems like I can't use this saved Cache however. Does anyone know if this is because the generated code has hardcoded memory addresses that will not work once the process has been restarted?
2)
If I use CompileOptions::kProduceParserCache it seems to work just fine. However I notice two problems.
a) Some files will not produce any data in the cache.
b) Those that do only generate 20 bytes of data, and loading this on subsequent compilations doesn't seems to speed up compilation at all.
Can anyone explain those two points?
Any other ideas on how it would be possible to speed up the initial loading of larger scripts? I assume we must be able to cache something, but so far I haven't had much success.
Thanks in advance.