-
Notifications
You must be signed in to change notification settings - Fork 436
fix(javascript): reserve writer capacity for write paths #3994
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
Changes from all commits
54ddaaa
df10f2e
1cbcacf
9169bf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,4 +213,36 @@ describe("map", () => { | |
| expect(serializer.deserialize(valid)).toEqual(value); | ||
| } | ||
| }); | ||
|
|
||
| test("should large declared map work", () => { | ||
| // The generated map write must reserve writer capacity for its entries. | ||
| // Without it, unchecked DataView writes past the buffer end threw a | ||
| // RangeError once the map body outgrew the initial buffer. | ||
| const fory = new Fory({ compatible: false }); | ||
| const { serialize, deserialize } = fory.register( | ||
| Type.struct( | ||
| { namespace: "example", typeName: "BigMap" }, | ||
| { m: Type.map(Type.int32({ encoding: "fixed" }), Type.int32({ encoding: "fixed" })) }, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This declared |
||
| ), | ||
| ); | ||
| const m = new Map<number, number>(); | ||
| for (let i = 0; i < 30000; i++) { | ||
| m.set(i, i + 1); | ||
| } | ||
| expect(deserialize(serialize({ m })).m.get(29999)).toBe(30000); | ||
| }); | ||
|
|
||
| test("should large any-typed map work", () => { | ||
| // A map with dynamic key/value types writes through MapAnySerializer, | ||
| // which must reserve writer capacity per entry. | ||
| // Numeric entries only: string bodies reserve internally, which would | ||
| // mask a missing per-entry reserve. | ||
| const fory = new Fory({ compatible: false }); | ||
| const { serialize, deserialize } = fory.register(Type.map(Type.any(), Type.any())); | ||
| const m = new Map<any, any>(); | ||
| for (let i = 0; i < 30000; i++) { | ||
| m.set(i, i % 2 === 0 ? BigInt(i) : i * 3); | ||
| } | ||
| expect(deserialize(serialize(m))).toEqual(m); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because every element is
1,writeElementsHeadersetsisSame = true, so this test exercises only the aggregate reserve. The per-item mixed-type reserves and thewriteDeclaredreserve can still be removed without this test failing. Please add a list larger than the initial writer buffer with mixed element types; ifwriteDeclaredis part of this fix, cover the unknown-Struct declared-list reserialization path as well.