Implements header write optimization for C6 v5 allocator by moving
header initialization from per-alloc time to carve time (during page
refill). This eliminates redundant header writes on the hot path.
Implementation:
- Added HAKMEM_SMALL_HEAP_V5_HEADER_MODE ENV (full|light, default: full)
- Added header_mode field to SmallHeapCtxV5 (cached per-thread)
- Modified alloc fast/slow paths to skip header write in light mode
- Modified refill to write headers during carve in light mode
- Free path unchanged (header validation still works)
Benchmark Results (2M iterations, ws=400):
C6-HEAVY (257-768B):
- Baseline (v5 OFF): 47.95 Mops/s
- v5 full mode: 38.97 Mops/s (-18.7% vs baseline)
- v5 light mode: 39.25 Mops/s (-18.1% vs baseline, +0.7% vs full)
MIXED 16-1024B:
- v5 OFF: 43.59 Mops/s
- v5 full mode: 36.53 Mops/s (-16.2% vs OFF)
- v5 light mode: 38.04 Mops/s (-12.7% vs OFF, +4.1% vs full)
Analysis:
- Light mode shows modest improvement over full (+0.7-4.1%)
- C6 v5 performance gap vs baseline (-18%) indicates need for
further optimization beyond header writes
- Mixed workload benefits more from light mode (+4.1% vs full)
- No regressions in safety/correctness observed
Research findings:
- Header write optimization alone insufficient to close v5 gap
- Need to investigate other hot path costs (freelist ops, metadata access)
- Light mode validates the carve-time header concept
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Single TLS segment (eliminates slot search loop)
- O(1) page_meta_of() (direct segment range check, no iteration)
- __builtin_ctz for O(1) free page finding in bitmap
- Simplified free path using page_meta_of() only (no find_page)
- Partial limit 1 (minimal list traversal)
Performance:
- Before (v5-2): 14.7M ops/s
- After (v5-3): 38.5M ops/s (+162%)
- vs baseline: 44.9M ops/s (-14%)
- SEGV: None, stable at ws=800
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>