We Spent a Sprint Optimizing JSON. The Profiler Said It Was 10% of the Problem.
Kevin Tung
0:00 / 0:00
We Spent a Sprint Optimizing JSON. The Profiler Said It Was 10% of the Problem.
4 просмотра · 9 дней назад
Kevin Tung
2 подписчика
4 просмотра · 9 дней назад
Everyone knew JSON was the hot spot. A quick CPU profile said regex compilation was about two-thirds and JSON about a tenth. Treat performance intuition as a hypothesis.
Alex and Maya dig into an illustrative composite: an order API's CPU kept climbing, a design review blamed JSON encoding within ten minutes, and the team spent a sprint on faster encoders and a hand-rolled serializer while CPU barely moved. Then a CPU profile showed the same email-validation regex being compiled on every request. They walk through Kevin's small, rerunnable Go example (one run, one machine: Go 1.24, GOMAXPROCS 8, -benchtime=2s): regexp.MustCompile 68.38% cumulative, runtime.mallocgc 39.34%, encoding/json.Marshal 10.29%; compiling the regex once took the function from 5826 to 816.7 ns/op (roughly 7x) and 69 to 3 allocs/op — a microbenchmark, not a 7x service. Then flat vs cumulative, 100 Hz sampling noise, benchmark traps (allocations, -count and benchstat, for b.Loop()), matching the profile type to the symptom, profiling production safely with pprof on a loopback-only listener, making "show me the profile" normal, Staff+ rules of thumb, and pushback.
Chapters:
0:00 Cold open — a sprint on JSON, CPU barely moved
1:53 The naive pattern: "everyone knows JSON is slow"
3:25 Failure timeline — the code everyone suspected
5:20 The experiment — benchmark and CPU profile
8:20 Reading the profile, and the five-minute fix
11:16 Benchmarks lie quietly, production profiling, FinOps
15:12 Staff+ rules of thumb
16:42 Making "show me the profile" normal, and pushback
17:42 Recap and reflective question
Question to sit with: when did you last change code for performance without a profile, and did the graph actually move? Could anyone on your team capture a production CPU profile in under five minutes today?
This discussion is based on a post by Kevin Tung. Read the written version on Medium: https://chen0625tung.medium.com/we-spent-a...
Hosts Alex and Maya are synthesized voices for this discussion (Microsoft Edge neural text-to-speech) and are not the author.
#Golang #Performance #Profiling #SoftwareEngineering #BackendDevelopment #DeveloperProductivity #pprof #StaffPlus