From 81dfa170b9719b8f62d61f8821cb30f361b368d1 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Wed, 3 Jul 2024 12:43:53 +0200 Subject: [PATCH 1/2] Add $typeName first --- package.json | 2 +- packages/bundle-size/README.md | 30 +++++++++++++++--------------- packages/bundle-size/chart.svg | 12 ++++++------ packages/bundle-size/package.json | 2 +- packages/protobuf/src/create.ts | 6 ++++-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 13f51efff..4a166a498 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ ], "scripts": { "clean": "git clean -Xdf", - "bundle-size": "turbo run report -F ./packages/bundle-size", + "bundle-size": "turbo run bundle-size -F ./packages/bundle-size", "perf": "turbo run perf -F ./packages/protobuf-test", "all": "turbo run build generate test lint attw bundle-size format license-header bootstrap:inject bootstrap:wkt", "setversion": "node scripts/set-workspace-version.js && npm run all", diff --git a/packages/bundle-size/README.md b/packages/bundle-size/README.md index 960c13a4a..6e86d4d06 100644 --- a/packages/bundle-size/README.md +++ b/packages/bundle-size/README.md @@ -10,23 +10,23 @@ usually do. We repeat this for an increasing number of files. ![chart](./chart.svg) -
Tabular data< /summary> +
Tabular data - + | code generator | files | bundle size | minified | compressed | -| ------------------- | ----- | ----------: | --------: | ---------: | -| protobuf-es | 1 | 125,817 b | 65,597 b | 15,272 b | -| protobuf-es | 4 | 128,006 b | 67,105 b | 15,919 b | -| protobuf-es | 8 | 130,768 b | 68,876 b | 16,418 b | -| protobuf-es | 16 | 141,218 b | 76,857 b | 18,753 b | -| protobuf-es | 32 | 169,009 b | 98,875 b | 24,198 b | -| protobuf-javascript | 1 | 339,613 b | 255,820 b | 42,481 b | -| protobuf-javascript | 4 | 366,281 b | 271,092 b | 43,912 b | -| protobuf-javascript | 8 | 388,324 b | 283,409 b | 45,038 b | -| protobuf-javascript | 16 | 548,365 b | 378,100 b | 52,204 b | -| protobuf-javascript | 32 | 1,240,889 b | 819,610 b | 78,780 b | - - +| ------------------- | ----: | ----------: | --------: | ---------: | +| protobuf-es | 1 | 125,855 b | 65,617 b | 15,259 b | +| protobuf-es | 4 | 128,044 b | 67,125 b | 15,961 b | +| protobuf-es | 8 | 130,806 b | 68,896 b | 16,468 b | +| protobuf-es | 16 | 141,256 b | 76,877 b | 18,761 b | +| protobuf-es | 32 | 169,047 b | 98,895 b | 24,249 b | +| protobuf-javascript | 1 | 334,193 b | 255,820 b | 42,481 b | +| protobuf-javascript | 4 | 360,861 b | 271,092 b | 43,912 b | +| protobuf-javascript | 8 | 382,904 b | 283,409 b | 45,038 b | +| protobuf-javascript | 16 | 542,945 b | 378,100 b | 52,204 b | +| protobuf-javascript | 32 | 1,235,469 b | 819,610 b | 78,780 b | + +
diff --git a/packages/bundle-size/chart.svg b/packages/bundle-size/chart.svg index 70c3a6abb..983a66133 100644 --- a/packages/bundle-size/chart.svg +++ b/packages/bundle-size/chart.svg @@ -43,14 +43,14 @@ 0 KiB - + protobuf-es -protobuf-es 14.91 KiB for 1 files -protobuf-es 15.55 KiB for 4 files -protobuf-es 16.03 KiB for 8 files -protobuf-es 18.31 KiB for 16 files -protobuf-es 23.63 KiB for 32 files +protobuf-es 14.9 KiB for 1 files +protobuf-es 15.59 KiB for 4 files +protobuf-es 16.08 KiB for 8 files +protobuf-es 18.32 KiB for 16 files +protobuf-es 23.68 KiB for 32 files diff --git a/packages/bundle-size/package.json b/packages/bundle-size/package.json index 49ded3f99..193147b6a 100644 --- a/packages/bundle-size/package.json +++ b/packages/bundle-size/package.json @@ -2,7 +2,7 @@ "name": "@bufbuild/bundle-size", "private": true, "scripts": { - "report": "tsx src/report.ts", + "bundle-size": "tsx src/report.ts", "pregenerate": "rm -rf src/gen", "generate": "buf generate buf.build/googleapis/googleapis:9475e2896f8a46d09806149f9382e538", "postgenerate": "license-header .", diff --git a/packages/protobuf/src/create.ts b/packages/protobuf/src/create.ts index 19f38d382..a6e5fad8d 100644 --- a/packages/protobuf/src/create.ts +++ b/packages/protobuf/src/create.ts @@ -200,7 +200,9 @@ const messagePrototypes = new WeakMap< function createZeroMessage(desc: DescMessage): Message { let msg: Record; if (!needsPrototypeChain(desc)) { - msg = {}; + msg = { + $typeName: desc.typeName, + }; for (const member of desc.members) { if (member.kind == "oneof" || member.presence == IMPLICIT) { msg[member.localName] = createZeroField(member); @@ -238,6 +240,7 @@ function createZeroMessage(desc: DescMessage): Message { messagePrototypes.set(desc, { prototype, members }); } msg = Object.create(prototype) as Record; + msg.$typeName = desc.typeName; for (const member of desc.members) { if (members.has(member)) { continue; @@ -255,7 +258,6 @@ function createZeroMessage(desc: DescMessage): Message { msg[member.localName] = createZeroField(member); } } - msg.$typeName = desc.typeName; return msg as Message; } From c73efff0639e2845fc0ead16a23697ed816099e6 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Wed, 3 Jul 2024 12:50:13 +0200 Subject: [PATCH 2/2] Remove perf and bundle-size scripts from root Root tasks can be confusing. We're better off with running turbo manually, if necessary with --filter. --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 4a166a498..68fbcc5d9 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,6 @@ ], "scripts": { "clean": "git clean -Xdf", - "bundle-size": "turbo run bundle-size -F ./packages/bundle-size", - "perf": "turbo run perf -F ./packages/protobuf-test", "all": "turbo run build generate test lint attw bundle-size format license-header bootstrap:inject bootstrap:wkt", "setversion": "node scripts/set-workspace-version.js && npm run all", "release": "npm run all && node scripts/release.js",