Skip to content

perf(encode,decode): skip reflect.Convert for exact map/slice types#51

Merged
xe-nvdk merged 1 commit intov6from
perf/map-encode-skip-convert
Mar 3, 2026
Merged

perf(encode,decode): skip reflect.Convert for exact map/slice types#51
xe-nvdk merged 1 commit intov6from
perf/map-encode-skip-convert

Conversation

@xe-nvdk
Copy link
Member

@xe-nvdk xe-nvdk commented Mar 3, 2026

Summary

  • Adds v.Type() == targetType fast path before v.Convert() in map and slice encode/decode functions
  • Convert is only needed for named types (e.g., type M map[string]string); for exact type matches it's pure overhead
  • Applies to map[string]string, map[string]bool, map[string]interface{}, and []string paths

Benchmark Results

StringSlice:         85 ns -> 79 ns  (-7%)
MapStringString:    192 ns -> 176 ns (-8%)
MapStringStringPtr: 217 ns -> 205 ns (-6%)

Test plan

  • All existing tests pass (including intern tests with named map types)
  • Benchmarks show consistent improvement

Adds v.Type() == targetType fast path before v.Convert() in map and
slice encode/decode functions. Convert is only needed for named types
(e.g. type M map[string]string); for exact type matches it's pure
overhead. Applies to map[string]string, map[string]bool,
map[string]interface{}, and []string paths.

Benchmark improvements:
  StringSlice:        85 ns -> 79 ns  (-7%)
  MapStringString:   192 ns -> 176 ns (-8%)
  MapStringStringPtr: 217 ns -> 205 ns (-6%)
@xe-nvdk xe-nvdk merged commit 5286520 into v6 Mar 3, 2026
3 checks passed
@xe-nvdk xe-nvdk deleted the perf/map-encode-skip-convert branch March 3, 2026 01:44
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