Skip to content

perf(schema): index name-mapping lookups - #1805

Open
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:perf/schema-name-mapping-index
Open

perf(schema): index name-mapping lookups#1805
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:perf/schema-name-mapping-index

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Build one name lookup index for each ApplyNameMapping call.
  • Reuse it for regular fields and list/map element, key, and value lookups.
  • Keep aliases scoped to their parent mapping field, so nested fields with the same name still resolve correctly.
  • Keep the exported NameMappingAccessor as the original empty, comparable type. The index is held by a private accessor used only by ApplyNameMapping.
  • Add alias and API-compatibility regression tests.
  • Add a wide-schema benchmark.

Why

Name mapping lookup previously scanned sibling fields for every schema field. On wide schemas, that repeated the same work and caused many allocations.

The new per-operation index builds the lookup once, then uses map lookups during traversal. It is private to each call and read-only after construction.

Benchmark

BenchmarkApplyNameMappingWideSchema with a 256-field schema on an Apple M1 Pro:

Metric Before After Result
Time/op 0.90 ms 37 us ~24x faster
Memory/op 2.16 MB 68 KB ~97% less
Allocs/op 32,921 31 ~99.9% fewer

Validation

  • go test ./...
  • go vet .
  • Wide-schema benchmark with -benchmem

@fallintoplace
fallintoplace marked this pull request as ready for review August 14, 2026 18:17
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.

1 participant