Skip to content

perf(go): prepare fixed collection key checks - #418

Merged
JasonXuDeveloper merged 5 commits into
mainfrom
codex/go-fixed-key-checks
Nov 19, 2026
Merged

JasonXuDeveloper merged 5 commits into
mainfrom
codex/go-fixed-key-checks

Conversation

@JasonXuDeveloper

Copy link
Copy Markdown
Owner

Changes

  • Prepare duplicate-key metadata once per generated Go key type and share it across sets and dictionaries. Eligible composite keys continue to use the reader's seeded, bounded table.
  • Select the primitive-entry comparer by type width and floating-point shape at compile time. The existing fixed-width map, set, grid, and DateTimeOffset collection paths use their direct codecs.
  • Follow the generated raw-memory fallback in the hand-written samples, with direct element codec calls. Preserve the exported callback APIs for their existing callers.

Verification

  • .NET SDK 11.0.100 Codegen and Integration passed 99 and 16 tests. Regenerated Go fixtures and benchmark model pass.
  • Go corpus, race, purego, Go 1.22.12 vet and tests, four fuzz targets, and QEMU 386, Arm32, and s390x passed. Arm32 needed the documented async-preemption retry.
  • x64 and Arm64 disassembly shows the static primitive comparison and direct raw fallbacks. Runner A/B measured eight-element Guid sets and eight-entry Guid maps taking 6–10% and 5–7% less time on the sampled x64 CPUs. Neoverse-N2 was on par. The 1,024-entry Guid map, scalar, and string controls stayed within 2% by CPU median.

The pre-existing Half and DateTime key-equality discrepancies are tracked in #417.

Closes #353


Generated by Codex

Keep the bulk copy for matching layouts and use fixed-stride calls on the portable path. Mirror the generated codecs while keeping the callback helpers available to their existing callers.

Refs #353
Share a typed duplicate check across generated collections with the same key type. Resolve the comparison metadata at package initialization, and select the primitive-entry comparison from the generic key type.

Refs #353

Performance: On sampled GitHub x64 runners, generated eight-element Guid sets took 6–10% less time and eight-entry Guid maps took 5–7% less time. Arm64 and the large-map, integer, and string controls were on par.
Record where generated codecs prepare key metadata and how the primitive entry path selects its comparison.
Record the Arm32 runtime fault reproduced under QEMU 10.0.13 and the retry settings that passed the Go suite.
Keep the per-architecture checks and explain the measured impact of preparing key metadata before decoding.
JasonXuDeveloper added a commit that referenced this pull request Nov 19, 2026
…inters

Keep #418 as a separate prerequisite and reconcile the shared generated shapes against both templates. The eight measured Go union functions reproduce the A/B source byte for byte.
@JasonXuDeveloper
JasonXuDeveloper merged commit 5fea67b into main Nov 19, 2026
36 checks passed
@JasonXuDeveloper
JasonXuDeveloper deleted the codex/go-fixed-key-checks branch November 19, 2026 06:11
JasonXuDeveloper added a commit that referenced this pull request Nov 19, 2026
Merges `origin/main` (06cbf9a) into `feat/storage-layer`. That brings
in 62 commits main has gained since the last sync, so the storage
layer's final PR into main has fewer conflicts. The merge had no
conflicts.

What came in:
- #401: TypeScript grids, and the runtime split into modules
- #414: skills record why Rust, Go and TypeScript keep their standard
block copies
- #418: Go runtime and nino-gen prepare duplicate-key checks once per
key type
- #419: Rust `impls` codec files kept in one module through ordered
`include!` fragments, and their rustfmt check in CI
- the other main commits since the last sync: Go, Rust and TypeScript
runtimes, nino-gen templates and fixtures, `Directory.Packages.props`
bumps, skills and docs

None of them touches Nino.Core or Nino.Generator. On the .NET side only
Nino.Codegen, its tests, the GeneratorBenchmark project and
`Directory.Packages.props` change.

Checked locally: `dotnet build` (0 warnings), `Nino.UnitTests` on
net10.0 (1,233 passed, 1 skipped), `tools/agents.sh --check`.

---
_Generated by [Claude Code](https://claude.ai/code)_
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/)_
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.

Close the Go runtime's fixed-size gaps

1 participant