Skip to content

perf: reduce newValue() allocations in typed map decode loop #65

@xe-nvdk

Description

@xe-nvdk

Problem

In `decodeTypedMapValue()`, `d.newValue(keyType)` and `d.newValue(valueType)` are called per map entry inside the decode loop (lines 300, 305 in decode_map.go). For a map with N entries, this creates 2N `reflect.New()` allocations.

Proposal

Allocate key and value `reflect.Value` once outside the loop, then reuse by calling `v.Set(reflect.Zero(t))` to reset between iterations. This reduces 2N allocations to 2.

Files

  • `decode_map.go` — `decodeTypedMapValue()` inner loop

Expected Impact

HIGH for typed map workloads — eliminates 2*(N-1) allocations per map decode. N is the number of map entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions