Skip to content

Commit

Permalink
Composer perf: preload components to avoid parsing javascript on “reply”
Browse files Browse the repository at this point in the history
  • Loading branch information
bengotow committed Feb 14, 2018
1 parent dbedb14 commit 22d9f20
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/global/mailspring-component-kit.es6
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
// `require` files the first time they're called.
module.exports = exports = {};

// Because requiring files the first time they're used hurts performance, we
// automatically load components slowly in the background using idle cycles.
setTimeout(() => {
const remaining = Object.keys(module.exports);
const fn = deadline => {
let key = null;
let bogus = 0; // eslint-disable-line
while ((key = remaining.pop())) {
bogus += module.exports[key] ? 1 : 0;
if (deadline.timeRemaining() <= 0) {
window.requestIdleCallback(fn, { timeout: 5000 });
return;
}
}
};
window.requestIdleCallback(fn, { timeout: 5000 });
}, 500);

const resolveExport = requireValue => {
return requireValue.default || requireValue;
};
Expand Down

0 comments on commit 22d9f20

Please sign in to comment.