API Design as a Performance Primitive
summary
Demonstrates a handbuilt streaming JSON parser that replaces encoding/json’s per-token allocation model with a sliding-window, provider-owned buffer window API, cutting token allocations from about 52 to 3 and showing ~10× tokenization throughput versus encoding/json, ~2–3× for a full decoder, and up to 10× with the bytes-oriented API. Uses a custom byteReader/scan/next flow, small reusable buffers (tunable from ~60 bytes to 4–8 KB), eliminates per-byte error checks, and delivers multi-hundred MB/s to low GB/s parsing with near-zero allocations.
AI-written summary · about
chapters (30)
- 0:00Introduction by host and speaker welcome
- 0:47Thesis on API design as performance primitive
- 1:53Goals and constraints for JSON decoder API design
- 3:44Why streaming JSON decoding is critical
- 5:08Complexity of JSON tokenization and parsing
- 8:17Cost of allocations in hot paths and garbage collection
- 9:27Understanding JSON tokenization basics
- 11:00Problems with encoding JSON token API
- 13:28Benchmarking encoding JSON token overhead
- 14:51Designing a new token API with byte slices
- 16:20Introducing package JSON and its API
- 18:30Benchmarking package JSON tokenization
- 20:15Challenges of efficient JSON reading
- 24:08Introducing byte reader for streaming data
- 27:01Byte reader API and mechanics
- 30:57Whitespace scanning with byte reader
- 33:25Benchmarking whitespace scanning performance
- 35:33Building a JSON scanner on byte reader
- 36:59Token function and whitespace skipping
- 39:02Error handling in scanner and byte reader
- 41:30Benchmarking scanner performance
- 43:20Performance impact of inlining scanner functions
- 46:18Validating JSON structure with state machine
- 47:46Optimizing state transitions with method expressions
- 50:15Outlining and inlining for decoder performance
- 52:47Final benchmark results and JSON decoder performance
- 54:57Key takeaways on API design and performance
- 57:10Limitations of I/O reader and writer APIs
- 58:34Introducing byte reader package and future ideas
- 1:00:19Q&A on error checking and API design trade-offs
related talks
30mCaching, Payloads, and Other Dark Arts
30mProcessing large JSON files without running out of memory
01h 03mExtreme Performance Architecture
27mHigh Performance Architecture
41mParsing Safely, from 500MB/s to 2GB/s
47mToward a High-Performance JSON Protocol: Notes
40mPerf Stories
21mHigh Performance APIs through Caching
