Skip to content

Commit

Permalink
perf: use brotli
Browse files Browse the repository at this point in the history
Runtime performance is roughly the same but the cache size shrinks:
```diff
$ du -s node_modules/.cache/yarn/
- 2212    node_modules/.cache/yarn/
+ 1464    node_modules/.cache/yarn/
```
  • Loading branch information
merceyz committed Feb 14, 2023
1 parent 813962a commit f1c7428
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/setup-ts-execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const cache = {

const cachePath = path.join(__dirname, `../node_modules/.cache/yarn/esbuild-transpile-cache.bin`);
try {
const cacheData = v8.deserialize(zlib.gunzipSync(fs.readFileSync(cachePath)));
const cacheData = v8.deserialize(zlib.brotliDecompressSync(fs.readFileSync(cachePath)));
if (cacheData.version === cache.version) {
cache.files = cacheData.files;
}
Expand All @@ -70,12 +70,16 @@ function persistCache() {
const tmpPath = cachePath + crypto.randomBytes(8).toString(`hex`);
fs.writeFileSync(
tmpPath,
zlib.gzipSync(
zlib.brotliCompressSync(
v8.serialize({
version: cache.version,
files: cache.files,
}),
{level: 1},
{
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 4,
},
},
),
);
fs.renameSync(tmpPath, cachePath);
Expand Down

0 comments on commit f1c7428

Please sign in to comment.