Skip to content

[shell-operator] chore: improve json performance#872

Open
ldmonster wants to merge 2 commits intomainfrom
chore/improve-json-performance
Open

[shell-operator] chore: improve json performance#872
ldmonster wants to merge 2 commits intomainfrom
chore/improve-json-performance

Conversation

@ldmonster
Copy link
Copy Markdown
Collaborator

Benchmark Results: goccy/go-json vs encoding/json

Marshal (encoding)

Payload go-json std json Speedup Alloc reduction
Small map (Pod metadata) 1,342 ns 1,708 ns 1.27x 4 vs 13 allocs
Medium map (full Pod) 12,469 ns 16,742 ns 1.34x 25 vs 104 allocs
Binding context (50 objects) 193,023 ns 244,743 ns 1.27x 447 vs 1,611 allocs
Binding context (500 objects) 2,004,233 ns 2,535,465 ns 1.26x 4,452 vs 16,011 allocs
Struct (10 MetricOperations) 6,195 ns 9,233 ns 1.49x 12 vs 52 allocs
AdmissionReview 14,915 ns 19,588 ns 1.31x 29 vs 119 allocs

Unmarshal (decoding)

Payload go-json std json Speedup Alloc reduction
Small map 1,715 ns 3,118 ns 1.82x 20 vs 25 allocs
Medium map 17,368 ns 23,213 ns 1.34x 187 vs 168 allocs
Binding context (50 objects) 242,985 ns 311,178 ns 1.28x 2,369 vs 2,082 allocs
Binding context (500 objects) 2,512,677 ns 3,141,470 ns 1.25x 23,522 vs 20,535 allocs
Struct (10 MetricOperations) 10,211 ns 31,216 ns 3.06x 83 vs 132 allocs
AdmissionReview 20,201 ns 32,358 ns 1.60x 203 vs 199 allocs

Encoder/Decoder (streaming)

Payload go-json std json Speedup
Encoder (500 obj binding ctx) 1,802,357 ns 2,402,493 ns 1.33x
Decoder (20 MetricOperations) 25,570 ns 66,858 ns 2.61x

Key takeaways

  • Struct unmarshal (used for MetricOperations, AdmissionReview parsing) sees the largest gain: 2.6-3.1x faster
  • Map marshal (used for binding contexts, checksum computation) is consistently 1.25-1.34x faster with 3.6x fewer allocations
  • Streaming decode (used for MetricOperationsFromReader, webhook request parsing) is 2.6x faster
  • go-json trades slightly more bytes-per-alloc for dramatically fewer allocation count on the marshal side, reducing GC pressure

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
@ldmonster ldmonster self-assigned this Apr 19, 2026
@ldmonster ldmonster added the enhancement New feature or request label Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant