loading...

Discussion on: Faster App Starts With Prepack & Webpack

Collapse
dubyabrian profile image
W. Brian Gourlie

"But Kay, isn't JavaScript blazing fast already?"

Javascript is pretty fast! And it's fast because modern browsers do this thing called just-in-time compilation, where it converts the unoptimized Javascript that you've written into highly-optimized machine code. But, the JIT itself is a relatively expensive process, so instead of compiling all your javascript, it runs your unoptimized code for a while, does a bit of analysis to determine what code would benefit the most from optimization, and then optimizes that code on-the-fly.

So what about all the code that the browser determines isn't worth just-in-time compiling? It sits there, unoptimized! The browser deemed that it isn't worth the runtime cost to optimize it. This is where prepack comes in.

Prepack does a bunch of analysis on your code to figure out what can be statically determined ahead-of-time. It can be thought of as doing a sort-of ahead-of-time compilation step, such that code that wouldn't otherwise be optimized by the JIT, is instead optimized ahead-of-time. And the benefit of an ahead-of-time compilation step is that it incurs zero runtime cost.