- use forEach instead of map (because return value was ignored)
- use Promise.all instead of parallel, because tasks are already Promise based. Fewer callbacks.
Added chokidar to watch for folder changes; added folder-watcher;
passing state to delayedInit on main; added default values for new
preferences; added “Auto add torrents” preference with its checkbox and
path selector; TODO: start/stop watching on preference change, start
watching on init, add dialog when trying to enable preference without a
torrents folder.
By deferring more code in the renderer and loading state earlier, we
improve startup time by another 90ms!
Before: 507 unique requires (1270-1280ms)
After: 506 unique requires (1180-1190ms)
In Electron apps, the cost of large modules is very real.
fs-extra is very convenient, but removing it caused 50 fewer unique
files to be required(), resultin in 60ms faster startup!
Before: 557 unique requires (1330-1340ms)
After: 507 unique requires (1270-1280ms)
Every require() that we do before the users sees UI reduces startup
time.
I used the following code (added to index.js) to log every require()
call in the main process:
```js
var Module = require('module')
var required = {}
Module.prototype.require = function (orig) {
return function (id) {
if (!required[id]) {
required[id] = true
console.log(`${id} (from ${this.filename})`)
}
return orig.apply(this, arguments)
}
}(Module.prototype.require)
```
From this I was able to learn that lots of modules were being required
that aren't actually used until later.
I also sent this related PR to eliminate another few require()s:
https://github.com/LinusU/node-application-config/pull/4
This increases startup time by 50ms.
We'll probably realize much bigger gains by following this same
procedure for the renderer process.
- Make State.save() always throttle calls -- since that's the common
case.
- Immediate saves are now the exception, with State.saveImmediate().
- The function is called State.save(), so the dispatch event should be
'stateSave'.