meteor / babel

Babel wrapper package for use with Meteor
Other
46 stars 20 forks source link

`util.deepHash` is slower than hashing JSON #8

Closed dgreensp closed 8 years ago

dgreensp commented 8 years ago

Changing this line to:

  var cacheHash = util.deepHash(meteorBabelVersion, source, JSON.stringify(options));

...more than doubles hashing performance. The simplest and most performant thing would probably be to drop deepHash and just take the SHA of JSON.stringify({meteorBabelVersion, source, options}).

Edit: Oops, since source is a really big string, maybe don't JSON the whole thing, just options, and use deepHash.

gadicc commented 8 years ago

The thing is, in babel-compiler, we already have a hash of the source from inputFile.getSourceHash().

With PR https://github.com/meteor/babel/pull/9, we could pass this as one of the deps and use it as a preference if it exists, without breaking backwards compatibility.

Happy to do this as a PR when we get to discussing this.

i.e.

var cacheHash;
if (deps && deps.sourceHash)
  cacheHash = sha1(JSON.stringify({meteorBabelVersion, options, deps});
else
  cacheHash = util.deepHash(meteorBabelVersion, source, options, deps);

(or simply avoid passing source to deepHash() if it's already provided via deps, which is what I ultimately did in PR #11).