Push Ifs Up and Fors Down: The Idiom, Its Algebra, and Its Limits
Tiger Style and matklad recommend pushing ifs up and fors down. This post looks at what the idiom actually says, where it shows up in query optimization and in the algebra of functional programs, and where the analogy stops paying for itself.
Niche Optimization in Rust: How `Option` can Get to Be Free
Most types cannot use every bit pattern their bytes can hold, and the Rust compiler spends the leftovers on enum discriminants. Where niches come from, and where the trick stops working.
How Miri found a data race in a lock-free ring buffer that the compiler had no way to see
A lock-free MPSC ring buffer passed its test suite, a Quint model check, loom, and cargo miri test - and was still undefined behaviour. A silent Deref widened every buffer reference to span the whole allocation, and a retag counts as an access.
Safety as Performance: Moves, the Borrow Checker, debug_assert!, and Cold-Path Hygiene
Rust's safety machinery is not a tax on performance but a tool for it: move semantics that delete copies, a borrow checker that deletes runtime guards, debug_assert! that vanishes in release, and cold-path hygiene that keeps the instruction cache clean.
Backoff & Memory Provisioning: Adaptive Spinning, Custom Allocators, NUMA & Huge Pages
Two resources a lock-free ring buffer takes for granted: time and memory. Adaptive backoff for waiting well, and a pluggable allocator trait for NUMA placement and huge pages.
Compile-Time Leverage: Specialization, Branch & Arithmetic Hygiene, and Inlining
How const generics, zero-sized types, branch and arithmetic hygiene, and disciplined inlining hand the Rust compiler enough compile-time facts to make sizes immediate, unused features free, and redundant checks disappear in a lock-free SPSC ring buffer.
Zero-Copy on the Hot Path: Reserve/Commit and Fast-Path/Slow-Path Splitting
How a reserve/commit protocol eliminates per-item copies in a lock-free SPSC ring buffer, and how fast-path/slow-path splitting keeps the common case branch-predictable.
Amortizing Cross-Core Coordination: Cursor Caching and Batch Processing
How cursor caching and batch processing amortize the cost of cross-core coordination in a lock-free SPSC ring buffer, so cores touch shared atomics a fraction as often.
The Cross-Core Contract: Memory Ordering and Single-Writer State in Lock-Free Rust
How Release/Acquire ordering, Relaxed counters, and single-writer UnsafeCell state make lock-free Rust ring buffers correct and efficient.
Cache-Conscious Data Layout in Rust: Field Zoning, False Sharing, and the 128-Byte Rule
How to lay out a shared Rust struct by who-touches-what - zoning fields by write owner and frequency, then padding the cross-core ones to avoid false sharing and prefetcher-induced contention.