Repository navigation
Introduce NativeCompileCache - #9318
Conversation
|
✨
I guess devtools disabled the cache optimization, devtools is known to affect V8's optimization when opened since it needs to receive full information of the JavaScript context. |
|
This seems to work pretty nicely and the I/O improvements made in b365ba5 seems to let Atom load within 670ms-690ms almost always on my machine. @maxbrunsfeld @nathansobo: I have polished up the code as well, so your feedback would be super appreciated! 🙏 @izuzak: features-wise nothing should have changed, but it would be great if you could have a look and try to break 💣 it. 🙇 |
b365ba5 to
71b6871
Compare
cbb6f21 to
f13e516
Compare
There was a problem hiding this comment.
What do you think about naming this class something generic like BlobStore, since its interface isn't specific to a caching use case? For me, I think that kind of name would more quickly communicate that the specific v8-code-caching logic lives in the NativeCompileCache, not here.
There was a problem hiding this comment.
Good call. 👍 I think I still like the explicitness of mentioning that this is a file-system cache, though: so, what about naming it FileSystemBlobStore?
There was a problem hiding this comment.
Yeah, I like that. It implements the BlobStore interface using the file-system.
There was a problem hiding this comment.
Another very minor thing, maybe NativeCompileCache::setCacheStorage -> ::setBlobStore?
|
❤️ Clean design. Clean tests. Super nice. |
|
Is there a reason the new bits are not written using Babel/ES2015? 😕 |
|
I commented above about using es6. Don't think we need babel though, now that we're on electron 34, unless we're using |
Does the ES6 bits in Electron support new module loader syntax (e.g. Also Other than the ES syntax comment, this looks great! Awesome job as usual @as-cii 👏 |
|
No, it doesn't support |
|
Also, in order to work in dev mode, in which files are transpiled on-the-fly, modules like these, that are loaded early in the startup process ( |
|
I've been using this branch this morning, and I can definitely feel the improvement in startup. |
bce16f6 to
27a6f36
Compare
@thomasjo @maxbrunsfeld: ❤️ ❤️ ❤️ I have just ported the code over ES6 and removed references to |
|
Is that |
There was a problem hiding this comment.
We might want to do this a different way, to avoid doing these two synchronous IPC calls to the browser process (.require and .on) during startup, and also to avoid contentious writes by multiple windows during shutdown. Maybe the browser process could actually control this in its before-quit callback, telling only one window to save its state, using some synchronous IPC method like WebContents::executeJavascript.
...so that we can pass BlobStore to AtomEnvironment
|
Thanks everyone for all the great suggestions! ✨ If needed we can refine this on a separate branch/commit. |
|
🐎🌠 |
|
Yeah!! Nice job @as-cii |
|
Fantastic work as usual, @as-cii! 🙇 |
|
Hey @as-cii: @kevinsawicki and I were talking yesterday and he brought up that we should include the v8 version in the compile cache key in case they change their internal formats. Did a quick audit and not sure this is currently happening, but we should probably get that in before this goes to beta if we can. |
V8 does have a built-in notion of rejecting a cache blob, and @as-cii has handled this case by deleting it from our blob-store, so we may not need to explicitly include it in the cache key. |
|
Oh right, that makes sense. They handle their own invalidation internally. |
This PR speeds up source code compile times by using a hacked version of the
vmmodule (https://github.com/as-cii/cached-run-in-this-context).We've been searching very hard for a way to make startup faster: the biggest low hanging fruit seemed to be
vm.runInThisContextwhich, before this improvement, took more than250ms-300ms. That function is used insideModule.prototype._compilefor, surprise, compiling the source code: although v8 compiler is quite fast already, our codebase has grown quite a lot and the more files we added, the worse the situation would get.The snapshot approach tried in #9265 should have indirectly solved this, but it felt way too complicated to construct an
AtomEnvironmentinside the snapshot context. Instead, we are taking advantage of a v8 compiler feature that allows to speed up source code compilation by producing/consuming a cache blob. By using this mechanism, we have managed to change startup times from (without any tab open):to:
🎉 🎉 🎉
There's still some aspect we could improve, such as where these cache blobs get stored: I used files as the storage mechanism, as it allows us to keep the code pretty simple, but they take ~40ms to get read. There are alternatives to this (e.g. asar), but I am not sure it would improve the situation that much: even a 50% improvement, would make this just ~20ms faster at the expense of making code a bit more complex.
Please, note that whenever DevTools are open, v8 seems to make this optimization a bit worse: if you, however, spawn Atom:
You will notice the speedup. @zcbenz: any ideas why this happens? I guess this covers already 100% of the average use cases and won't matter to the end user, but if possible it seems to be still worth investigating.
After this lands, I will go on hunting other things that are slowing startup down: we feel like IO could be the main cause but we'll get a better picture after this improvement gets 🚢ped.
/cc: @atom/feedback @nathansobo