I’ve been doing a bunch of research into the startup times of NativeScript apps in an attempt to document best practices, and there’s something I’ve noticed but can’t explain—the webpack plugin’s
--uglify flag consistently speeds up my apps, and I have no idea why.
In my testing uglification drops startup times something like ~20–40%, which is crazy. On my Mac, the default NativeScript app starts up on a Nexus 5 emulator in ~2 seconds (using
npm run ns-bundle), and that time drops to ~1.5 seconds with
npm run ns-bundle --android --uglify. I’m also not the only one that’s noticed this optimization (see https://twitter.com/eddyverbruggen/status/873506250096619520).
So... um, why does this work?
It’s my understanding that the primary reason webpack speeds up my apps is by reducing file I/O—that is, webpack combines a bunch of files that would normally have to be retrieved one-at-a-time with
require() calls. That makes sense to me. But what about uglification would speed up my apps?
To my knowledge uglify is primarily doing things that reduce the file size of my code—thing like removing whitespace, and shortening variable names—so I can see why it might reduce the file size of my app. But I’m not sure how that translates to a faster loading experience, as it would seem like the NativeScript runtime would still have to interpret the same amount of expressions regardless.
Is the uglification process doing something like removing dead code? Is there something else going on that I’m just missing? If anyone has any ideas here I’d really appreciate it. I haven’t done extensive benchmarking, so I might just be testing this wrong.