Skip to content

Commit

Permalink
Use MD4 instead of SHA1 for filename hashes (#639)
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 authored and hzoo committed Jul 5, 2018
1 parent a23f1c3 commit 2be502d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cache.js
Expand Up @@ -62,13 +62,13 @@ const write = async function(filename, result) {
* @return {String}
*/
const filename = function(source, identifier, options) {
const hash = crypto.createHash("SHA1");
const hash = crypto.createHash("md4");

const contents = JSON.stringify({ source, options, 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 2be502d

Please sign in to comment.