ameshkov / diffupdates

Filter lists diff updates proposal
17 stars 2 forks source link

Move from SHA1 to SHA256 #4

Open jvoisin opened 8 months ago

jvoisin commented 8 months ago

It's absolutely not critical, since SHA1 is only used for cache invalidation, but it would still be a good idea to move to SHA256:

Local benchmarks ```console $ openssl speed sha1 sha256 The 'numbers' are in 1000s of bytes per second processed. type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 16384 bytes sha1 327375.88k 845549.18k 1661196.46k 2138193.24k 2340312.41k 2455983.45k sha256 309979.54k 752303.40k 1443518.89k 1855458.65k 2044474.71k 2044116.99k ``` ```console $ cat ./bench.js const fs = require('fs'); const data = fs.readFileSync('./easylist.txt', 'utf8'); const Benchmark = require('benchmark'); const suite = new Benchmark.Suite; const hash = require('crypto').createHash; const scenarios = [ { alg: 'sha1', digest: 'hex' }, { alg: 'sha1', digest: 'base64' }, { alg: 'sha256', digest: 'hex' }, { alg: 'sha256', digest: 'base64' } ]; for (const { alg, digest } of scenarios) { suite.add(`${alg}-${digest}`, () => hash(alg).update(data).digest(digest) ); } suite.on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')); }) .run(); $ nodejs bench.js sha1-hex x 691 ops/sec ±0.56% (95 runs sampled) sha1-base64 x 689 ops/sec ±1.39% (95 runs sampled) sha256-hex x 575 ops/sec ±4.05% (84 runs sampled) sha256-base64 x 624 ops/sec ±1.86% (89 runs sampled) Fastest is sha1-hex $ nodejs --version v12.22.12 $
ameshkov commented 8 months ago

I'll keep it open, we'll consider changes to the spec later when we have more real-life experience with how it works.