A Fast Structured Logging Package
summary
New structured logging package slog for Go 1.21 aims for zap-level speed and exposes a concrete Logger plus a more-complex Handler API that enables backend optimizations. Benchmarks run in parallel and use benchstat; typical calls use 5 attributes (captures ~95%) and ~8 constructors (95%). Fast path is log.Adders (avoids variadic slice heap alloc), records copy-by-value with an inline array sized 5 to avoid allocations, uses unsafe string data packing to eliminate interface boxing, and deliberately avoids sync.Pool to prevent use-after-free.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:23slog API demo
- 2:47Why slog needed speed
- 4:13Performance goals
- 5:38Logging patterns analysis
- 7:04Concurrent logging benchmarks
- 9:12Handler architecture
- 11:58Avoiding indirect calls
- 13:00Heap vs stack trade-offs
- 15:05Variadic args and escape analysis
- 16:51Byte slice optimizations
- 17:53sync.Pool for zero allocations
- 18:41Passing records by value
- 19:28Preallocating attribute arrays
- 21:14slog.value optimizations
- 22:42Zero-allocation values
- 24:47Design lessons
- 25:30Summary
related talks
46mStructured Logging for the Standard Library
20mStructured Logging for the Standard Library
23mFrom OOP to Go
21mContextual Logging for Modern Go Applications
14mMemory Optimization through Structure Packaging
37mFluent Bit: Extending Your Logging Pipeline with Go
48mBlazing Fast Merge with Loser Trees
01h 02mKeeping it Simple With Go
