Repository navigation
Tree shaking and optimizations - #1225
Conversation
This reverts commit b094627.
|
Alright, I think this is ready for an initial look now. I'm now bundling dugite as well and keeping just the git environment external. I also had to manually copy the 7zip dependency (in dev mode) so that electron-devtools-installer could do its work. |
shiftkey
left a comment
There was a problem hiding this comment.
This is really close - the test deploy of this branch is working nicely on macOS and Windows, just a couple of minor suggestions ✨.
| console.log(' Copying git environment…') | ||
| const gitDir = path.resolve(outRoot, 'git') | ||
| fs.mkdirpSync(gitDir) | ||
| fs.copySync(path.resolve(projectRoot, 'app/node_modules/dugite/git'), gitDir) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| "test:review": "node script/test-review", | ||
| "postinstall": "cd app && npm install && cd .. && git submodule update --recursive --init && npm run compile:tslint", | ||
| "start": "cross-env NODE_ENV=development node script/start", | ||
| "start:prod": "cross-env NODE_ENV=production node script/start", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| }) | ||
| } | ||
|
|
||
| const run = require('./run') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| "build:prod": "npm run compile:prod && cross-env NODE_ENV=production node script/build", | ||
| "package": "node script/package", | ||
| "clean": "rimraf build", | ||
| "clean": "rimraf out", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
🔒 |


I got bored this weekend and I started working on an old side project. As I was upgrading it to use the latest and greatest technologies I got curious about how big of an impact tree shaking would have on desktop.
Before you read any further please note that this is mostly an exploratory thing and its primary purpose is to open it up for discussion, the code quality is utter shite in places.
What this does
Updates us to use webpack2
I don't think this is strictly necessary but it was what I was using in my side-project so I figured it would make sense to upgrade
Enables tree shaking
Previously we simply copied the entire node_modules directory from the app directory into the dist directory and called it a day. This approach makes it very easy to reason about modules but it has the downside of bringing along a lot of resources that we don't need (build scripts, package.json files, tests, fixtures etc). Tree shaking is a fancy word for bringing in just the code that's needed at runtime and bundling that along with the rest of the bundle.
With tree shaking enabled we only have to copy dugite, right now I explicitly copy it over from the node_modules folder since we can safely ignore all of its dependencies as they are only for install. A better approach here would be to include the dugite library in the tree shaking as well and only copy the git binaries to a known location. That would require a change to dugite so that we can pass a known location via an environment variable or something to that effect.
Dead code elimination
As part of the babili preset we get dead code elimination which, in combination with our webpack replacements completely removes things like
if(__DEV__) {...}. React makes heavy use ofNODE_ENV !== 'production', those checks are now all gone in release builds as well.Parallel compillation
This PR uses parallel-webpack to speed up compilation, each bundle gets its own little web worker.
TypeScript caching
I've switched from
ts-loadertoawesome-typescript-loaderwhich gives us a compile cache that allows us to bypass typescript transpiling for files that haven't changed. It also runs typechecking in a separate process which frees up cycles on the main worker.Misc
The measurements
I've only tested this on my machine running Windows so take all of these with a grain of salt. For reference my machine is pretty beefy with PCIe SSD, 32Gb ram, i7-6700HQ @ 2.60 GHz etc etc so I would expect the gains in loadtime to be higher for the majority of our users and even more so for users without fast disks as our node_modules approach ends up hitting the file system quite a bit and that's way more expensive on Windows than on Mac (where I'd expect these gains to be less grand)
Bottom line
Enabling tree shaking, minification, and optimization would yield some reasonably good results at the cost of a pretty significantly increased build time (though only for production builds, dev builds would be faster). I would take an increase in prod build time for the gains at runtime but I'm curious to hear everyone's thoughts.
Fixes #1089, #487