Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(perf) avoid object.keys on hot path for performance - simplify #772

Merged
merged 2 commits into from
Jan 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/babel-plugin-minify-simplify/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
const VOID_0 = t => t.unaryExpression("void", t.numericLiteral(0), true);

// Types as Symbols - for comparing types
// init must be empty object -
// computing this involves checking object.keys() to be of length 0
// skipped otherwise
const types = {};
// This is a test key which is used to avoid Object.keys check
// Object.keys() check is really expensive
// https://gist.github.com/vigneshshanmugam/c766550ecd02292dcdfbf0bf013b9d3d
const testKey = "Expression";

const typeSymbols = t => {
// don't recompute
if (Object.keys(types).length < 1) {
t.TYPES.forEach(type => {
types[type] = Symbol.for(type);
});
if (types[testKey] !== undefined) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yields around 300-400ms on average - Results -> https://gist.github.com/vigneshshanmugam/c766550ecd02292dcdfbf0bf013b9d3d

return types;
}
t.TYPES.forEach(type => {
types[type] = Symbol.for(type);
});
return types;
};

Expand Down