Skip to content

v1.9.2 reuse array elements dropped by a shrink when decoding in place - #24

Merged
reececomo merged 1 commit into
mainfrom
fix/reuse-shrunk-array-elements
Nov 10, 2026
Merged

reececomo merged 1 commit into
mainfrom
fix/reuse-shrunk-array-elements

Conversation

@reececomo

Copy link
Copy Markdown
Owner

In-place decoding now reuses array element objects dropped by a shrink when the array grows again, so arrays of varying length stop allocating.

More details

Before, _$readArray truncated the target array, which discarded the element objects past the new length. The next longer packet then allocated fresh ones, along with any nested arrays and objects inside them. Elements dropped by a shrink are now kept in a per-array spare pool (a WeakMap) and handed back to _$read when the array grows. Scalar arrays are unaffected.

In a probe of 1,000 in-place decodes of { frames: [{ seq, inputs: [{ x: Scalar8, y: Scalar8 }] }] } with varying lengths, new objects fell from 14,282 to 0 after warm-up.

One behaviour changes: an element object removed by a shrink can reappear, overwritten, after a later grow. The existing deep-object test asserted the old behaviour, so that assertion now expects reuse.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@reececomo
reececomo marked this pull request as ready for review November 10, 2026 10:35
@reececomo
reececomo merged commit 98829ee into main Nov 10, 2026
2 checks passed
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