Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch code size benchmark to use fflate #411

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,5 @@ release: all ## Release @bufbuild/protobuf

.PHONY: checkdiff
checkdiff:
@# Used in CI to verify that `make` doesn't produce a diff, but ignore changes in benchmarks
git checkout packages/protobuf-bench/README.md
@# Used in CI to verify that `make` doesn't produce a diff
test -z "$$(git status --porcelain | tee /dev/stderr)"
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/protobuf-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ server would usually do.

| code generator | bundle size | minified | compressed |
|---------------------|------------------------:|-----------------------:|-------------------:|
| protobuf-es | 86,785 b | 36,950 b | 9,654 b |
| protobuf-javascript | 394,384 b | 288,775 b | 45,201 b |
| protobuf-es | 86,785 b | 36,950 b | 11,079 b |
| protobuf-javascript | 394,384 b | 288,775 b | 54,825 b |
1 change: 1 addition & 0 deletions packages/protobuf-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@bufbuild/buf": "^1.14.0-1",
"@bufbuild/protobuf": "1.0.0",
"esbuild": "^0.17.10",
"fflate": "^0.7.4",
"google-protobuf": "3.21.2"
}
}
12 changes: 6 additions & 6 deletions packages/protobuf-bench/report.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildSync } from "esbuild";
import { brotliCompressSync } from "zlib";
import { gzipSync } from "fflate";

const protobufEs = gather("src/entry-protobuf-es.ts");
const googleProtobuf = gather("src/entry-google-protobuf.js");
Expand All @@ -23,7 +23,11 @@ server would usually do.
function gather(entryPoint) {
const bundle = build(entryPoint, false, "esm");
const bundleMinified = build(entryPoint, true, "esm");
const compressed = compress(bundleMinified);
const compressed = gzipSync(bundleMinified, {
mtime: 0,
level: 6,
mem: 6,
});
return {
entryPoint,
size: formatSize(bundle.byteLength),
Expand All @@ -47,10 +51,6 @@ function build(entryPoint, minify, format) {
return result.outputFiles[0].contents;
}

function compress(buf) {
return brotliCompressSync(buf);
}

function formatSize(bytes) {
return new Intl.NumberFormat().format(bytes) + " b";
}