perf: 90ms improvement: Defer more code in renderer, load state earlier

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)
This commit is contained in:
Feross Aboukhadijeh
2016-09-30 22:00:58 -07:00
parent 02f5dbb63f
commit 5ff2d893b9
4 changed files with 49 additions and 28 deletions

View File

@@ -6,6 +6,8 @@ const config = require('../../config')
const SAVE_DEBOUNCE_INTERVAL = 1000
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
const State = module.exports = Object.assign(new EventEmitter(), {
getDefaultPlayState,
load,
@@ -16,13 +18,11 @@ const State = module.exports = Object.assign(new EventEmitter(), {
// After first State.save() invokation, future calls go straight to the
// debounced function
State.save = debounce(saveImmediate, SAVE_DEBOUNCE_INTERVAL)
State.save()
State.save(...arguments)
},
saveImmediate
})
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
function getDefaultState () {
const LocationHistory = require('location-history')