Skip to content

Commit

Permalink
avoid object.keys on hot path for performance - simplify (#772)
Browse files Browse the repository at this point in the history
* removing symbol logic for performance

* remove object keys check to improve performance
  • Loading branch information
vigneshshanmugam authored and boopathi committed Jan 7, 2018
1 parent 4c55d3d commit 879f25e
Showing 1 changed file with 10 additions and 7 deletions.
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) {
return types;
}
t.TYPES.forEach(type => {
types[type] = Symbol.for(type);
});
return types;
};

Expand Down

0 comments on commit 879f25e

Please sign in to comment.