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

V2: Add $typeName first #923

Merged
merged 2 commits into from
Jul 3, 2024
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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
],
"scripts": {
"clean": "git clean -Xdf",
"bundle-size": "turbo run report -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",
Expand Down
30 changes: 15 additions & 15 deletions packages/bundle-size/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ usually do. We repeat this for an increasing number of files.

![chart](./chart.svg)

<details><summary>Tabular data< /summary>
<details><summary>Tabular data</summary>

<!--- TABLE-START -->
<!-- TABLE-START -->

| 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 |

<!--- TABLE-END -->
| ------------------- | ----: | ----------: | --------: | ---------: |
| 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 |

<!-- TABLE-END -->

</details>
12 changes: 6 additions & 6 deletions packages/bundle-size/chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/bundle-size/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@bufbuild/bundle-size",
"private": true,
"scripts": {
"report": "tsx src/report.ts",
"bundle-size": "tsx src/report.ts",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was silently broken.

"pregenerate": "rm -rf src/gen",
"generate": "buf generate buf.build/googleapis/googleapis:9475e2896f8a46d09806149f9382e538",
"postgenerate": "license-header .",
Expand Down
6 changes: 4 additions & 2 deletions packages/protobuf/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ const messagePrototypes = new WeakMap<
function createZeroMessage(desc: DescMessage): Message {
let msg: Record<string, unknown>;
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);
Expand Down Expand Up @@ -238,6 +240,7 @@ function createZeroMessage(desc: DescMessage): Message {
messagePrototypes.set(desc, { prototype, members });
}
msg = Object.create(prototype) as Record<string, unknown>;
msg.$typeName = desc.typeName;
for (const member of desc.members) {
if (members.has(member)) {
continue;
Expand All @@ -255,7 +258,6 @@ function createZeroMessage(desc: DescMessage): Message {
msg[member.localName] = createZeroField(member);
}
}
msg.$typeName = desc.typeName;
return msg as Message;
}

Expand Down