Skip to content

Core: Precompute sorted entries in ShreddedObject SerializationState#17114

Open
nssalian wants to merge 1 commit into
apache:mainfrom
nssalian:variant-shredded-writeto
Open

Core: Precompute sorted entries in ShreddedObject SerializationState#17114
nssalian wants to merge 1 commit into
apache:mainfrom
nssalian:variant-shredded-writeto

Conversation

@nssalian

@nssalian nssalian commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Changes

Precomputes a sorted Entry[] once in the SerializationState constructor.
writeTo becomes an index loop over the array.

Per-writeTo, this removes:

  • SortedMerge.of(...) + two stream().sorted() iterators
  • 2N HashMap lookups (shreddedFields.get + unshreddedFields.get)
  • The Maps.newHashMap(shredded) defensive copy

The Maps.newHashMap(shredded) copy was there to stop the old code from accidentally
modifying the caller's map (#15087). The refactor never modifies the caller's map, so the copy is no longer needed.

Tests

Three new tests in TestShreddedObject:

  • testPutAfterRemoveIsSerialized - remove(x) then put(x, v) semantics
  • testEmptyObject - zero-field state
  • testRepeatedWriteToProducesSameBytes - cached-state reuse across writes
  • Ran additional diff tests locally from the main branch to ensure correctness.

@github-actions github-actions Bot added the core label Jul 6, 2026
@nssalian nssalian force-pushed the variant-shredded-writeto branch from 518e15e to a5f6fab Compare July 6, 2026 18:02
@nssalian nssalian marked this pull request as ready for review July 6, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants