Skip to content

Optimize dynamic schemas#1255

Merged
adwsingh merged 1 commit into
mainfrom
adwsingh/dynamic-schemas-perf
Jun 19, 2026
Merged

Optimize dynamic schemas#1255
adwsingh merged 1 commit into
mainfrom
adwsingh/dynamic-schemas-perf

Conversation

@adwsingh

Copy link
Copy Markdown
Contributor

What behavior changes?

No observable behavior change. Dynamic-schema document serde produces the same
output for the same input. This is purely internal: less allocation and faster
serialize/deserialize for StructDocument / ContentDocument, especially for
union-dense payloads (e.g. DynamoDB AttributeValue) and string/enum lists.

Why is this change needed?

Performance. The old path wrapped every leaf value in a second Document and
stored struct members in a LinkedHashMap keyed by member name. This added an
allocation per leaf plus map overhead per struct. The hot serialize call site
was also megamorphic, so C2 couldn't inline it.

How was this validated?

  • Existing dynamic-schemas unit tests pass (./gradlew :dynamic-schemas:test).
  • Serde benchmarks (the dynamic-client serde bench) used to measure the
    allocation / throughput wins.
  • Protocol tests pass.

What should reviewers focus on?

  • ContentDocument: now stores the raw unwrapped value (String/Number/Boolean/
    Instant/ByteBuffer/List/Map) instead of wrapping a Document. Look at
    serializeContents / serializeScalar (kept in sync by hand) and the
    string/enum list fast-path in serializeListContents.
  • StructDocument + SchemaGuidedDocumentBuilder: struct members now live in a
    member-index-keyed Document[] instead of a LinkedHashMap; unions store the
    single set value raw (no ContentDocument wrapper). Reusable consumer objects
    replace per-call closures.
  • SchemaDocument: the one case that still wraps a Document (untyped
    document-typed members).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@adwsingh adwsingh force-pushed the adwsingh/dynamic-schemas-perf branch from 391dd60 to a6abf91 Compare June 18, 2026 02:36
@adwsingh adwsingh changed the title Perf optimizations Optimize dynamic schemas Jun 18, 2026
@adwsingh adwsingh requested a review from mtdowling June 18, 2026 04:35
@adwsingh adwsingh force-pushed the adwsingh/dynamic-schemas-perf branch from a6abf91 to 3155849 Compare June 19, 2026 19:16
@adwsingh adwsingh merged commit 9908243 into main Jun 19, 2026
5 checks passed
@adwsingh adwsingh deleted the adwsingh/dynamic-schemas-perf branch June 19, 2026 19:38
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.

2 participants