Skip to content

perf: optimize schema and serde hot paths - #367

Open
jterapin wants to merge 36 commits into
mainfrom
serde-opt/6-optimizations
Open

jterapin wants to merge 36 commits into
mainfrom
serde-opt/6-optimizations

Conversation

@jterapin

@jterapin jterapin commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Optimizes schema, serde, and client hot paths on top of the merged schema-extension foundation.

  • Flattens and independently resolves schema, JSON, XML, and HTTP extension metadata.
  • Reuses frozen JSON, XML, and CBOR codec workers across calls.
  • Keeps XML build state local so worker reuse remains thread-safe.
  • Reduces JSON, XML, and CBOR encoding and decoding allocations.
  • Simplifies shape dispatch and removes redundant metadata lookups.
  • Reduces client request preparation, conversion, validation, host-prefix, and response-status overhead.

Each commit isolates one optimization or correctness follow-up so the changes can be reviewed incrementally.

Review guide

Recommended review order:

  1. Schema and extension metadata

    • Flat, namespaced metadata keys replace grouped hashes.
    • Boolean and nullable values use fetch_metadata where ||= would not memoize them.
    • Runtime shape dispatch uses shape classes instead of cached numeric tags.
  2. Serde codecs

    • JSON, XML, and CBOR reuse frozen workers owned by each codec.
    • Workers retain configuration only; per-call state remains local.
    • XML passes its DocBuilder through each build rather than storing it on the reusable worker.
  3. Allocation reductions

    • CBOR avoids temporary byte strings and repeated header decoding.
    • JSON and XML builders reduce intermediate objects and repeated lookups.
    • Client paths reuse resolved targets and cached metadata.
  4. Safety and compatibility

    • String-based trait lookups remain in extension and serde paths for dynamic-client support.
    • Generic runtime union and float dispatch remains.
    • Sequential and concurrent codec reuse is covered by tests.
    • RBS signatures match the updated runtime APIs.

Non-goals

  • No protocol wire-format behavior changes.
  • No code-generated serde redesign.
  • No removal of runtime union or float dispatch.
  • No changes to timestamp precision.

Compatibility

The corresponding AWS Query and REST schema-extension changes have merged into aws-sdk-ruby-staging version-4 through PRs #76, #77, #78, #80, and #81.

Validation

  • All GitHub CI checks pass.
  • smithy-schema: 137 examples, 0 failures.
  • smithy-json: 69 examples, 0 failures.
  • smithy-xml: 58 examples, 0 failures.
  • smithy-cbor: 268 examples, 0 failures.
  • smithy-client: 889 examples, 0 failures, 2 pre-existing pending.
  • Schema, JSON, XML, CBOR, and client RBS validation passed.
  • Full RuboCop: 366 files, no offenses.
  • Full staging specs and generated protocol suites passed during stack validation.

@jterapin
jterapin force-pushed the serde-opt/6-optimizations branch 2 times, most recently from 44d61ee to fd298ea Compare September 14, 2026 18:17
@jterapin jterapin changed the title perf: use cached schema metadata for log filtering perf: reuse cached helpers across serde codecs Sep 14, 2026
@jterapin
jterapin force-pushed the serde-opt/6-optimizations branch from fd298ea to 0c30860 Compare September 14, 2026 18:44
@jterapin
jterapin force-pushed the serde-opt/6-optimizations branch from 0c30860 to 85b754e Compare September 14, 2026 19:47
@jterapin
jterapin marked this pull request as ready for review September 14, 2026 20:34
@jterapin
jterapin requested a review from a team as a code owner September 14, 2026 20:34
@jterapin
jterapin added this pull request to stack #370 September 14, 2026 20:34
# @return [String, nil]
def build(shape, data)
Builder.new(@options).build(shape, data)
@builder.build(shape, data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could using the same builder each time build is called cause multithreading issues? Previously each time build was called a new Builder was created.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. I ended up making some changes so that we don't use any per-call state from now on. When we switch protocols, the codecs are re-init.

An error occurred while trying to automatically change base from serde-opt/5-client-consumers to main September 21, 2026 16:50
jterapin added a commit that referenced this pull request Sep 21, 2026
## Summary

Migrates Smithy client plugins and parameter handling to the cached
Schema metadata established by the earlier foundation PRs.

- Migrates default parameters, parameter conversion, and validation to
cached target-shape and collection metadata.
- Uses cached required-member, streaming, host-label, idempotency-token,
and event-stream metadata.
- Uses cached operation metadata for checksum, host prefix, request
compression, retry long-polling, and transfer encoding.
- Retains a narrow trait fallback only for non-model operation doubles
in retry tests.

## Out of scope

- Serde micro-optimizations and compatibility fixes in #367 and #369.
- Legacy helper removal in #366.
- Staging runtime/regeneration work.

## Validation

- smithy-client RBS task: 839 examples, 0 failures, 2 expected pending.
- RuboCop and git diff --check passed.
jterapin added a commit that referenced this pull request Sep 21, 2026
## Summary

Removes the obsolete Schema legacy_wire_name compatibility helper after
the migrated consumers no longer need it.

- Migrates Schema document deserialization to the canonical cached wire
index.
- Removes legacy_wire_name, its RBS declaration, and focused
compatibility coverage.

## Merge order

Merge after #367 and #369. GitHub does not allow this existing stacked
PR to be retargeted, so it remains based on #365.

## Validation

- smithy-schema RBS task: 135 examples, 0 failures.
- git diff --check passed.
@jterapin
jterapin force-pushed the serde-opt/6-optimizations branch from 85b754e to 91f7cc6 Compare September 21, 2026 17:55
@jterapin
jterapin removed this pull request from stack #370 September 21, 2026 17:58
@jterapin
jterapin changed the base branch from serde-opt/5-client-consumers to main September 21, 2026 17:58
@jterapin jterapin changed the title perf: reuse cached helpers across serde codecs perf: optimize schema and serde hot paths Sep 23, 2026
@jterapin
jterapin marked this pull request as ready for review September 23, 2026 20:14
@jterapin
jterapin added this pull request to stack #371 September 23, 2026 20:19
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