Skip to content

Commit

Permalink
deps: switch to chromium's zlib implementation
Browse files Browse the repository at this point in the history
This implementation provides optimizations not included upstream.

PR-URL: #31201
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
mscdex authored and codebytere committed Feb 17, 2020
1 parent 2eeaa5c commit bf7097c
Show file tree
Hide file tree
Showing 266 changed files with 11,399 additions and 39,711 deletions.
32 changes: 32 additions & 0 deletions benchmark/zlib/createInflate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');

const bench = common.createBenchmark(main, {
inputLen: [16 * 1024 * 1024],
chunkLen: [1024],
n: [1e2]
});

function main({ n, inputLen, chunkLen }) {
const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));

let i = 0;
bench.start();
(function next() {
let p = 0;
const inflater = zlib.createInflate();
inflater.resume();
inflater.on('finish', () => {
if (i++ === n)
return bench.end(n);
next();
});

(function nextChunk() {
if (p >= input.length)
return inflater.end();
inflater.write(input.slice(p, p += chunkLen), nextChunk);
})();
})();
}
37 changes: 37 additions & 0 deletions benchmark/zlib/inflate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');

const bench = common.createBenchmark(main, {
method: ['inflate', 'inflateSync'],
inputLen: [1024],
n: [4e5]
});

function main({ n, method, inputLen }) {
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));

let i = 0;
switch (method) {
// Performs `n` single inflate operations
case 'inflate':
const inflate = zlib.inflate;
bench.start();
(function next(err, result) {
if (i++ === n)
return bench.end(n);
inflate(chunk, next);
})();
break;
// Performs `n` single inflateSync operations
case 'inflateSync':
const inflateSync = zlib.inflateSync;
bench.start();
for (; i < n; ++i)
inflateSync(chunk);
bench.end(n);
break;
default:
throw new Error('Unsupported inflate method');
}
}
5 changes: 4 additions & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@
'RuntimeLibrary': '<(MSVC_runtimeType)',
'RuntimeTypeInfo': 'false',
}
}
},
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
},
}
},

Expand Down
Loading

0 comments on commit bf7097c

Please sign in to comment.