Go low latency patterns
summary
Diagnoses a real legacy hotspot where an update function runs millions of times per second and causes 30% CPU due to GC by allocating on each call, then shows fixes: change field assignment, preallocate once, or switch parameter types. Demonstrates escape-analysis quirks (the con t46 runtime small-value cache at 0xFF/256), compares exact-type, interface and generic parameter behavior and inlining rules, and describes pointer-return patterns plus the dangerous NoEscape workaround. Recommends verify escape output and prefer allocate-once and value returns when predictable latency matters.
AI-written summary · about
chapters (18)
- 0:00Introduction and speaker info
- 1:04What is latency and performance basics
- 2:29Real-world GC overhead example
- 3:35Talk agenda overview
- 3:55Interfaces and heap allocation
- 8:12Avoiding heap allocation with interfaces
- 9:18Exact type vs interface parameters
- 11:26Generics and heap allocation
- 12:09Inlining optimizations explained
- 13:14Interface vs generic performance comparison
- 15:01Choosing between interfaces and generics
- 16:32Pointers and heap allocation pitfalls
- 17:57Safe pointer return patterns
- 18:40Performance in math/big package
- 19:27Custom stack-allocated types
- 20:11NoEscape function and risks
- 21:18Escape analysis verification tips
- 22:02Q&A session
