diff --git a/package.json b/package.json index ee34bebf..4625e62f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "iso-639-1": "^1.2.1", "languagedetect": "^1.1.1", "location-history": "^1.0.0", + "lodash.merge": "^4.6.0", "material-ui": "^0.15.4", "mkdirp": "^0.5.1", "musicmetadata": "^2.0.2", @@ -102,7 +103,7 @@ "package": "node ./bin/package.js", "prepublish": "npm run build", "start": "npm run build && electron .", - "test": "standard && depcheck --ignores=buble,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js", + "test": "standard && depcheck --ignores=buble,lodash.merge,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js", "update-authors": "./bin/update-authors.sh", "watch": "nodemon --exec \"npm run start\" --ext js,pug,css --ignore build/ --ignore dist/" } diff --git a/src/renderer/main.js b/src/renderer/main.js index d8cb504d..1687c85b 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -1,3 +1,22 @@ +/** + * Perf optimization: Hook into require() to modify how certain modules load: + * + * - `lodash/merge` (used by `material-ui`) causes 119 require() calls at startup, + * which take ~100ms. Replace it with `lodash.merge` which is equivalent. + * See: https://github.com/callemall/material-ui/pull/4380#issuecomment-250894552 + * + * - `inline-style-prefixer` (used by `material-ui`) takes ~40ms. It is not + * actually used because auto-prefixing is disabled with + * `darkBaseTheme.userAgent = false`. Return a fake object. + */ +let Module = require('module') +const _require = Module.prototype.require +Module.prototype.require = function (id) { + if (id === 'lodash/merge') id = 'lodash.merge' + if (id === 'inline-style-prefixer') return {} + return _require.apply(this, arguments) +} + console.time('init') const crashReporter = require('../crash-reporter')