Skip to content

perf(encode): cache isZeroer check to skip interface boxing#50

Merged
xe-nvdk merged 1 commit intov6from
perf/isempty-cache-iszeroer
Mar 3, 2026
Merged

perf(encode): cache isZeroer check to skip interface boxing#50
xe-nvdk merged 1 commit intov6from
perf/isempty-cache-iszeroer

Conversation

@xe-nvdk
Copy link
Member

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

Summary

  • Caches whether each struct field type implements isZeroer at struct-discovery time (maybeZeroer field)
  • Skips v.Interface().(isZeroer) boxing in isEmptyValue when the type doesn't implement the interface
  • Avoids heap allocation from interface boxing on every field during OmitEmpty checks

Details

The isEmptyValue function previously called v.Interface().(isZeroer) on every field value, which boxes the value into an interface{} (heap allocation) even when the type doesn't implement isZeroer. Now the check is cached once per field at struct registration time, and the boxing is skipped entirely for fields whose types don't implement the interface.

Test plan

  • All existing tests pass
  • Benchmarks verified — no regressions

…yValue

Caches whether each struct field's type implements isZeroer at
struct-discovery time. When it doesn't (the common case), skips
the v.Interface().(isZeroer) type assertion in isEmptyValue,
avoiding heap allocation from interface boxing on every field
during OmitEmpty checks.
@xe-nvdk xe-nvdk merged commit 3019618 into v6 Mar 3, 2026
3 checks passed
@xe-nvdk xe-nvdk deleted the perf/isempty-cache-iszeroer branch March 3, 2026 01:44
xe-nvdk added a commit that referenced this pull request Mar 3, 2026
The method became dead code after PR #50 switched Omit() to call
isEmptyValueHint directly.
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