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: Avoid the prototype chain with editions if possible #897

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions packages/bundle-size/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ usually do. We repeat this for an increasing number of files.
<!--- TABLE-START -->
| code generator | files | bundle size | minified | compressed |
|-----------------|----------|------------------------:|-----------------------:|-------------------:|
| protobuf-es | 1 | 125,758 b | 65,554 b | 15,210 b |
| protobuf-es | 4 | 127,947 b | 67,062 b | 15,882 b |
| protobuf-es | 8 | 130,709 b | 68,833 b | 16,446 b |
| protobuf-es | 16 | 141,159 b | 76,814 b | 18,708 b |
| protobuf-es | 32 | 168,950 b | 98,830 b | 24,189 b |
| protobuf-es | 1 | 126,056 b | 65,701 b | 15,280 b |
| protobuf-es | 4 | 128,245 b | 67,211 b | 15,969 b |
| protobuf-es | 8 | 131,007 b | 68,982 b | 16,474 b |
| protobuf-es | 16 | 141,457 b | 76,963 b | 18,779 b |
| protobuf-es | 32 | 169,248 b | 98,979 b | 24,215 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 |
Expand Down
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.
28 changes: 28 additions & 0 deletions packages/protobuf-test/src/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as example_ts from "./gen/ts/extra/example_pb.js";
import * as proto3_ts from "./gen/ts/extra/proto3_pb.js";
import * as proto2_ts from "./gen/ts/extra/proto2_pb.js";
import * as edition2023_ts from "./gen/ts/extra/edition2023_pb.js";
import * as test_messages_proto3_editions_ts from "./gen/ts/editions/golden/test_messages_proto3_editions_pb.js";
import { fillProto3Message, fillProto3MessageNames } from "./helpers-proto3.js";
import {
fillEdition2023Message,
Expand Down Expand Up @@ -153,6 +154,12 @@ describe("create()", () => {
expect(msg.mapInt32WrappedUint32Field).toStrictEqual({});
expect(hasOwn("mapInt32WrappedUint32Field")).toBe(true);
});
test("without custom prototype", () => {
const msg = create(desc);
const hasCustomPrototype =
Object.getPrototypeOf(msg) !== Object.prototype;
expect(hasCustomPrototype).toBe(false);
});
});
describe("from proto2", () => {
const desc = proto2_ts.Proto2MessageSchema;
Expand Down Expand Up @@ -323,6 +330,12 @@ describe("create()", () => {
expect(msg.mapInt32WrappedUint32Field).toStrictEqual({});
expect(hasOwn("mapInt32WrappedUint32Field")).toBe(true);
});
test("with custom prototype", () => {
const msg = create(desc);
const hasCustomPrototype =
Object.getPrototypeOf(msg) !== Object.prototype;
expect(hasCustomPrototype).toBe(true);
});
});
describe("from edition2023", () => {
const desc = edition2023_ts.Edition2023MessageSchema;
Expand Down Expand Up @@ -502,6 +515,21 @@ describe("create()", () => {
expect(msg.mapInt32WrappedUint32Field).toStrictEqual({});
expect(hasOwn("mapInt32WrappedUint32Field")).toBe(true);
});
test("with custom prototype", () => {
const msg = create(desc);
const hasCustomPrototype =
Object.getPrototypeOf(msg) !== Object.prototype;
expect(hasCustomPrototype).toBe(true);
});
});
describe("from edition2023 with proto3 features", () => {
const desc = test_messages_proto3_editions_ts.TestAllTypesProto3Schema;
test("without custom prototype", () => {
const msg = create(desc);
const hasCustomPrototype =
Object.getPrototypeOf(msg) !== Object.prototype;
expect(hasCustomPrototype).toBe(false);
});
Comment on lines +525 to +532
Copy link
Member Author

Choose a reason for hiding this comment

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

We're using editions/golden/test_messages_proto3_editions.proto to test that an editions file with file option features.field_presence = IMPLICIT does not use the prototype chain.

});
});

Expand Down
Loading