Skip to content

Commit 309858c

Browse files
mscdexcodebytere
authored andcommitted
deps: switch to chromium's zlib implementation
This implementation provides optimizations not included upstream. PR-URL: #31201 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 8661fa6 commit 309858c

File tree

266 files changed

+11399
-39711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+11399
-39711
lines changed

benchmark/zlib/createInflate.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const zlib = require('zlib');
4+
5+
const bench = common.createBenchmark(main, {
6+
inputLen: [16 * 1024 * 1024],
7+
chunkLen: [1024],
8+
n: [1e2]
9+
});
10+
11+
function main({ n, inputLen, chunkLen }) {
12+
const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
13+
14+
let i = 0;
15+
bench.start();
16+
(function next() {
17+
let p = 0;
18+
const inflater = zlib.createInflate();
19+
inflater.resume();
20+
inflater.on('finish', () => {
21+
if (i++ === n)
22+
return bench.end(n);
23+
next();
24+
});
25+
26+
(function nextChunk() {
27+
if (p >= input.length)
28+
return inflater.end();
29+
inflater.write(input.slice(p, p += chunkLen), nextChunk);
30+
})();
31+
})();
32+
}

benchmark/zlib/inflate.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const zlib = require('zlib');
4+
5+
const bench = common.createBenchmark(main, {
6+
method: ['inflate', 'inflateSync'],
7+
inputLen: [1024],
8+
n: [4e5]
9+
});
10+
11+
function main({ n, method, inputLen }) {
12+
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
13+
14+
let i = 0;
15+
switch (method) {
16+
// Performs `n` single inflate operations
17+
case 'inflate':
18+
const inflate = zlib.inflate;
19+
bench.start();
20+
(function next(err, result) {
21+
if (i++ === n)
22+
return bench.end(n);
23+
inflate(chunk, next);
24+
})();
25+
break;
26+
// Performs `n` single inflateSync operations
27+
case 'inflateSync':
28+
const inflateSync = zlib.inflateSync;
29+
bench.start();
30+
for (; i < n; ++i)
31+
inflateSync(chunk);
32+
bench.end(n);
33+
break;
34+
default:
35+
throw new Error('Unsupported inflate method');
36+
}
37+
}

common.gypi

+4-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@
236236
'RuntimeLibrary': '<(MSVC_runtimeType)',
237237
'RuntimeTypeInfo': 'false',
238238
}
239-
}
239+
},
240+
'xcode_settings': {
241+
'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
242+
},
240243
}
241244
},
242245

0 commit comments

Comments
 (0)