Skip to content

Commit

Permalink
V2: Avoid the prototype chain with editions if possible (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Jun 21, 2024
1 parent 5e19fc4 commit 3a7393b
Show file tree
Hide file tree
Showing 8 changed files with 2,207 additions and 16 deletions.
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,535 b | 65,455 b | 15,230 b |
| protobuf-es | 4 | 127,724 b | 66,962 b | 15,891 b |
| protobuf-es | 8 | 130,486 b | 68,733 b | 16,411 b |
| protobuf-es | 16 | 140,936 b | 76,714 b | 18,716 b |
| protobuf-es | 32 | 168,727 b | 98,732 b | 24,208 b |
| protobuf-es | 1 | 125,833 b | 65,603 b | 15,257 b |
| protobuf-es | 4 | 128,022 b | 67,111 b | 15,948 b |
| protobuf-es | 8 | 130,784 b | 68,882 b | 16,433 b |
| protobuf-es | 16 | 141,234 b | 76,863 b | 18,756 b |
| protobuf-es | 32 | 169,025 b | 98,881 b | 24,210 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);
});
});
});

Expand Down
Loading

0 comments on commit 3a7393b

Please sign in to comment.