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')

View File

@@ -2,6 +2,7 @@
// Reports back so that we can improve WebTorrent Desktop
module.exports = {
init,
send,
logUncaughtError,
logPlayAttempt
}
@@ -22,7 +23,9 @@ function init (state) {
telemetry = state.saved.telemetry = createSummary()
reset()
}
}
function send (state) {
const now = new Date()
telemetry.version = config.APP_VERSION
telemetry.timestamp = now.toISOString()
@@ -223,7 +226,7 @@ function getElemString (elem) {
let ret = elem.tagName
try {
ret += '.' + Array.from(elem.classList).join('.')
} catch (e) {}
} catch (err) {}
return ret
}