Skip to content

[Go] Size struct-codec groups from decoded entries, not the wire count - #1143

Open
slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:go-struct-group-capacity
Open

slachiewicz wants to merge 1 commit into
aeron-io:masterfrom
slachiewicz:go-struct-group-capacity

Conversation

@slachiewicz

Copy link
Copy Markdown
Contributor

When decoding from an io.Reader, the struct codecs allocated make([]T, numInGroup) from the count on the wire, so a 4-byte group header claiming 65534 entries made Car.Decode allocate 2 MiB before reading any entry. A new slice now starts at no more than 1024 entries and grows as entries decode; a slice the caller passes in with enough capacity is reused as before. If decoding fails partway through a group, the slice now holds the entries decoded so far rather than the full count.

1024 keeps a single allocation for typical group sizes while bounding what a header alone can claim (about 32 KiB for Car's fuel figures).

Verified: the new GroupCapacity_test.go fails on master (2097200 bytes allocated) and passes with this change; make test in gocode passes. On arm64 Linux, decoding a fresh Car allocates the same (464 B, 11 allocs) and shows no time difference beyond run-to-run noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant