Skip to content

Commit

Permalink
Use MD4 instead of SHA1 for filename hashes
Browse files Browse the repository at this point in the history
We don't need the cryptographic strength of SHA-1 for this purpose, so
we may as well use a faster hashing algorithm.

While I was at it, I also sapped out the use of hash.end + hash.read
combo for the faster and more conventional hash.update + hash.digest. In
my local testing, this also seems to offer a nice speed boost.
  • Loading branch information
lencioni committed Jul 5, 2018
1 parent 8544ffa commit 19fb463
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/fs-cache.js
Expand Up @@ -71,16 +71,16 @@ const write = function(filename, result, callback) {
* @return {String}
*/
const filename = function(source, identifier, options) {
const hash = crypto.createHash("SHA1");
const hash = crypto.createHash("md4");
const contents = JSON.stringify({
source: source,
options: options,
identifier: identifier,
});

hash.end(contents);
hash.update(contents);

return hash.read().toString("hex") + ".json.gz";
return hash.digest("hex") + ".json.gz";
};

/**
Expand Down

0 comments on commit 19fb463

Please sign in to comment.