Repository navigation
perf(codegen): optimize Rust and TypeScript union codecs - #402
Merged
Merged
Conversation
The generated value wrappers escape when the decoder returns an interface. Keep the dynamic type available to callers that assert a concrete value case. Capture the escape-analysis command to distinguish boxing from the direct pointer cases. Refs #387
Return the new enum from its read and use the default read_into implementation to replace the old value. Track deferred class bodies only in cases that can introduce them, while retaining the union depth check on every nonempty value. Refs #387 Performance: Generated Rust codecs read union cases directly and record deferred bodies only for cases that can contain them.
Record the runner evidence and the nesting and deferral invariants for the generated union path.
Combine the type ID with a fixed-size payload in a single reservation. Emit the payload through the existing offset writers, including zeroing when the shape has padding. Refs #387 Performance: Generated TypeScript unions reserve the type ID and fixed-size payload together.
Record the Node runner evidence for folding a union tag and its fixed payload into one reservation.
JasonXuDeveloper
added a commit
that referenced
this pull request
Nov 19, 2026
**Merge #418 first.** Both changes regenerate the same Go shapes fixture. This branch includes #418 and the combined regeneration. The eight measured Go union codec functions are identical to the A/B candidate. ## Go Use pointers for generated cases that would allocate an interface box. Keep direct string and static small cases as values. Decode collections into bounded, typed blocks per pointer case. Each decode owns its storage and the published case IDs and payload bytes are preserved. ### Go source API Regenerate the bindings and use pointer literals and assertions for the affected cases, for example `&ChoiceInt32{Value: 42}` and `case *ChoiceInt32`. ### Evidence - Both official union payloads round-trip byte for byte. The linked benchmark readers on amd64 and Arm64 have zero of the five previous interface boxing calls. - [Runner A/B](https://github.com/JasonXuDeveloper/Nino/actions/runs/44458051073) measured 808 → 77 allocations for `UnionArray` and 582 → 43 for `TaggedUnionArray` on both architectures. Read medians fell 12–15% and 9–20% on x64, and 22% and 16% on Neoverse-N2. Allocation bytes fell 2.2% and 0.5%. The Xeon 6975P-C tagged write point estimate rose 5.2% with 10% baseline variation and `p=0.065`. The other write medians stayed within 5%. - .NET SDK 11.0.100 Codegen and Integration passed 99 and 16 tests. The Go race and required corpus suites, Go 1.22 vet, four fuzz targets, and QEMU 386, Arm32 and s390x passed. New cases exercise pointer lifetime, typed nil, recursive unions, map/grid storage and tracked cycles. ## Rust Retain the enum with a boxed class case. Inlining the measured class payload removed a box per class case and increased the 64-bit enum stride from 24 to 40 bytes. The end-to-end read took 31–33% more time on sampled x64 AMD CPUs and 36% more on Neoverse-N2. [Inline-class runner comparison](https://github.com/JasonXuDeveloper/Nino/actions/runs/44458051073) The merged Rust reader from #402 already leads postcard and bincode on both official union cases on all sampled x64 and Arm64 CPUs. [Same-run competitor comparison](https://github.com/JasonXuDeveloper/Nino/actions/runs/44451141322) ## TypeScript Use a direct value for the first case of each runtime type test and keep the tag for additional ambiguous cases. Equal values from different numeric cases keep distinct wire IDs. The official 1,000-element tagged payload reads back with 333 tagged case objects. Regenerate bindings and handle direct values in consumers that inspect case tags. - [Runner A/B](https://github.com/JasonXuDeveloper/Nino/actions/runs/44458051073) reduced tagged write medians by 14–16% on sampled x64 CPUs and 20% on Neoverse-N2. Tagged reads took about 12% less time on the sampled AMD CPUs and 17% less on Neoverse-N2, with the Xeon case on par. The plain union stayed on par. - Both official payloads round-trip byte for byte. V8 emits 124 and 235 bytes of bytecode for the generated tagged reader and writer and inlines them into the collection loops. Node, browser-mode and Wasm-disabled tests passed. The existing plain union already uses direct case values, and its writer was on par with JSON on Neoverse-N2. [#402 runner comparison](https://github.com/JasonXuDeveloper/Nino/actions/runs/44333395182) Closes #387 --- _Generated by [Codex](https://openai.com/codex/)_
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Verification
UnionArray/TaggedUnionArraydeserialize time by 38% / 51% on EPYC 9V74, 43% / 55% on Xeon 6975P-C and 33% / 44% on Neoverse-N2. The Rust serialization controls stayed on par.UnionArray/TaggedUnionArrayserialize time by 17% / 22% on Neoverse-N2 and 10–14% / 17–23% across the sampled x64 CPUs. The Arm64 plain union measured 37.1 µs against JSON's 38.8 µs, within 5%.Go value wrappers escape when returned through the union interface. Returning pointers would change the concrete dynamic types callers can assert. The Go allocation item remains open.
Refs #387
Generated by Codex