Open aabtop opened 4 years ago
Okay, some preliminary support for caching the snapshot for the TypeScript Compiler is added in 552cef1eaf86e5a9e8d266b42d2bd83dd4b0a4de . It is disabled by default, for reasons mentioned in the commit message.
I saw the time for jeep.ts and spiral_stack.ts drop from ~750ms to ~550ms, so that's not too shabby! And this is without any kind of "warming up". I experimented with warming up the code, but didn't see a huge improvement in speed.
Added a top-level switch to make it easy to continue to experiment with snapshots in 57b81d65d25b6f16989b557a3a64325ff33c0800.
On my laptop the time went from ~2s to ~1.65s.
Startup delay for a simple TS file is not terrible right now (~100-200ms), but it's not nothing either.
This delay was introduced when moving from JS to TS. I haven't profiled it yet so it's possible that it is caused by the TypeScript compiler running on the input file, however I suspect it is more likely the fact that we're now having V8 compile the TypeScript compiler on startup each time. The TSC is ~8mb unminified and ~2mb minified.
A great example source of how to setup a V8 snapshot is given by V8's mksnapshot tool: https://github.com/v8/v8/blob/master/src/snapshot/mksnapshot.cc . This tool may work for us, but I believe it is designed to be used internally by the v8 codebase. There is a fair bit of complexity as well around how to handle cross-compilation for different CPU architectures, which is handled already in the V8 build system, but this project doesn't have direct access to that logic.
One nice compromise is to cache a snapshot on startup to a user's cache directory, so that it's guaranteed to run on the device.