Changes:
- smallmid_is_in_range(): Add __attribute__((always_inline))
- mid_is_in_range(): Add __attribute__((always_inline))
Expected: Reduce function call overhead in Front Gate routing
Result: Neutral performance (~72M ops/s, same as Phase 1 final)
Analysis:
- Compiler was already inlining these simple functions with -O3 -flto
- 36M branches identified by perf are NOT from Front Gate routing
- Most branches are inside allocators (tiny_alloc, free, etc.)
- Front Gate optimization had minimal impact, as predicted
Next: SuperSlab size optimization (clear 3-5% benefit expected)
Files:
- core/hakmem_smallmid.h:116-119
- core/hakmem_mid_mt.h:228-231
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
IMPLEMENTATION:
===============
Add dynamic boundary adjustment between Tiny and Mid allocators via
HAKMEM_TINY_MAX_CLASS environment variable for performance tuning.
Changes:
--------
1. hakmem_tiny.h/c: Add tiny_get_max_size() - reads ENV and maps class
to max usable size (default: class 7 = 1023B, can reduce to class 5 = 255B)
2. hakmem_mid_mt.h/c: Add mid_get_min_size() - returns tiny_get_max_size() + 1
to ensure no size gap between allocators
3. hak_alloc_api.inc.h: Replace static TINY_MAX_SIZE with dynamic
tiny_get_max_size() call in allocation routing logic
4. Size gap fix: Mid's range now dynamically adjusts based on Tiny's max
(prevents 256-1023B from falling through when HAKMEM_TINY_MAX_CLASS=5)
A/B BENCHMARK RESULTS:
======================
Config A (Default, C0-C7, Tiny up to 1023B):
128B: 6.34M ops/s | 256B: 6.34M ops/s
512B: 5.55M ops/s | 1024B: 5.91M ops/s
Config B (Reduced, C0-C5, Tiny up to 255B):
128B: 1.38M ops/s (-78%) | 256B: 1.36M ops/s (-79%)
512B: 1.33M ops/s (-76%) | 1024B: 1.37M ops/s (-77%)
FINDINGS:
=========
✅ Size gap fixed - no OOM crashes with HAKMEM_TINY_MAX_CLASS=5
❌ Severe performance degradation (-76% to -79%) when reducing Tiny coverage
❌ Even 128B degraded (should still use Tiny) - possible class filtering issue
⚠️ Mid's coarse size classes (8KB/16KB/32KB) cause fragmentation for small sizes
HYPOTHESIS:
-----------
Mid allocator uses 8KB blocks for all 256-1024B allocations, causing:
- Severe internal fragmentation (1024B request → 8KB block = 87% waste)
- Poor cache utilization
- Consistent ~1.3M ops/s across all sizes (same 8KB class)
RECOMMENDATION:
===============
**Keep default HAKMEM_TINY_MAX_CLASS=7 (C0-C7, up to 1023B)**
Reducing Tiny coverage is COUNTERPRODUCTIVE with current Mid allocator design.
To make this viable, Mid would need finer size classes for 256B-8KB range.
ENV USAGE (for future experimentation):
----------------------------------------
export HAKMEM_TINY_MAX_CLASS=7 # Default (C0-C7, up to 1023B)
export HAKMEM_TINY_MAX_CLASS=5 # Reduced (C0-C5, up to 255B) - NOT recommended
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>