dcc1d42e7f
Phase 6-2: Promote Front FastLane Free DeDup (default ON)
...
Results:
- A/B test: +5.18% on Mixed (10-run, clean env)
- Baseline: 46.68M ops/s
- Optimized: 49.10M ops/s
- Improvement: +2.42M ops/s (+5.18%)
Strategy:
- Eliminate duplicate header validation in front_fastlane_try_free()
- Direct call to free_tiny_fast() when dedup enabled
- Single validation path (no redundant checks)
Success factors:
1. Complete duplicate elimination (free path optimization)
2. Free path importance (50% of Mixed workload)
3. Improved execution stability (CV: 1.00% → 0.58%)
Phase 6 cumulative:
- Phase 6-1 FastLane: +11.13%
- Phase 6-2 Free DeDup: +5.18%
- Total: ~+16-17% from baseline (multiplicative effect)
Promotion:
- Default: HAKMEM_FRONT_FASTLANE_FREE_DEDUP=1 (opt-out)
- Added to MIXED_TINYV3_C7_SAFE preset
- Added to C6_HEAVY_LEGACY_POOLV1 preset
- Rollback: HAKMEM_FRONT_FASTLANE_FREE_DEDUP=0
Files modified:
- core/box/front_fastlane_env_box.h: default 0 → 1
- core/bench_profile.h: added to presets
- CURRENT_TASK.md: Phase 6-2 GO result
Health check: PASSED (all profiles)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 17:38:21 +09:00
f301ee4df3
chore: fix FastLane default comment
2025-12-14 16:30:32 +09:00
ea221d057a
Phase 6: promote Front FastLane (default ON)
2025-12-14 16:28:23 +09:00
4124c86d99
Phase 5: freeze E5-4 malloc tiny direct (neutral)
2025-12-14 06:59:35 +09:00
580e7f4fa3
Phase 5 E5-3: Candidate Analysis (All DEFERRED) + E5-4 Instructions
...
E5-3 Analysis Results:
- free_tiny_fast_cold (7.14%): DEFER - cold path, low ROI
- unified_cache_push (3.39%): DEFER - already optimized
- hakmem_env_snapshot_enabled (2.97%): DEFER - low headroom
Key Insight: perf self% is time-weighted, not frequency-weighted.
Cold paths appear hot but have low total impact.
Next: E5-4 (Malloc Tiny Direct Path)
- Apply E5-1 winning pattern to malloc side
- Target: tiny_alloc_gate_fast() gate tax elimination
- ENV gate: HAKMEM_MALLOC_TINY_DIRECT=0/1
Files added:
- docs/analysis/PHASE5_E5_3_ANALYSIS_AND_RECOMMENDATIONS.md
- docs/analysis/PHASE5_E5_4_MALLOC_TINY_DIRECT_NEXT_INSTRUCTIONS.md
- core/box/free_cold_shape_env_box.{h,c} (research box, not tested)
- core/box/free_cold_shape_stats_box.{h,c} (research box, not tested)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-14 06:44:04 +09:00
f7b18aaf13
Phase 5 E5-2: Header Write-Once (NEUTRAL, FROZEN)
...
Target: tiny_region_id_write_header (3.35% self%)
- Hypothesis: Headers redundant for reused blocks
- Strategy: Write headers ONCE at refill boundary, skip in hot alloc
Implementation:
- ENV gate: HAKMEM_TINY_HEADER_WRITE_ONCE=0/1 (default 0)
- core/box/tiny_header_write_once_env_box.h: ENV gate
- core/box/tiny_header_write_once_stats_box.h: Stats counters
- core/box/tiny_header_box.h: Added tiny_header_finalize_alloc()
- core/front/tiny_unified_cache.c: Prefill at 3 refill sites
- core/box/tiny_front_hot_box.h: Use finalize function
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (WRITE_ONCE=0): 44.22M ops/s (mean), 44.53M ops/s (median)
- Optimized (WRITE_ONCE=1): 44.42M ops/s (mean), 44.36M ops/s (median)
- Improvement: +0.45% mean, -0.38% median
Decision: NEUTRAL (within ±1.0% threshold)
- Action: FREEZE as research box (default OFF, do not promote)
Root Cause Analysis:
- Header writes are NOT redundant - existing code writes only when needed
- Branch overhead (~4 cycles) cancels savings (~3-5 cycles)
- perf self% ≠ optimization ROI (3.35% target → +0.45% gain)
Key Lessons:
1. Verify assumptions before optimizing (inspect code paths)
2. Hot spot self% measures time IN function, not savings from REMOVING it
3. Branch overhead matters (even "simple" checks add cycles)
Positive Outcome:
- StdDev reduced 50% (0.96M → 0.48M) - more stable performance
Health Check: PASS (all profiles)
Next Candidates:
- free_tiny_fast_cold: 7.14% self%
- unified_cache_push: 3.39% self%
- hakmem_env_snapshot_enabled: 2.97% self%
Deliverables:
- docs/analysis/PHASE5_E5_2_HEADER_REFILL_ONCE_DESIGN.md
- docs/analysis/PHASE5_E5_2_HEADER_REFILL_ONCE_AB_TEST_RESULTS.md
- CURRENT_TASK.md (E5-2 complete, FROZEN)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 06:22:25 +09:00
8875132134
Phase 5 E5-1: Free Tiny Direct Path (+3.35% GO)
...
Target: Consolidate free() wrapper overhead (29.56% combined)
- free() wrapper: 21.67% self%
- free_tiny_fast_cold(): 7.89% self%
Strategy: Single header check in wrapper → direct call to free_tiny_fast()
- Eliminates redundant header validation (validated twice before)
- Bypasses cold path routing for Tiny allocations
- High coverage: 48% of frees in Mixed workload are Tiny
Implementation:
- ENV gate: HAKMEM_FREE_TINY_DIRECT=0/1 (default 0)
- core/box/free_tiny_direct_env_box.h: ENV gate
- core/box/free_tiny_direct_stats_box.h: Stats counters
- core/box/hak_wrappers.inc.h: Wrapper integration (lines 593-625)
Safety gates:
- Page boundary guard ((ptr & 0xFFF) != 0)
- Tiny magic validation ((header & 0xF0) == 0xA0)
- Class bounds check (class_idx < 8)
- Fail-fast fallback to existing paths
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (DIRECT=0): 44.38M ops/s (mean), 44.45M ops/s (median)
- Optimized (DIRECT=1): 45.87M ops/s (mean), 45.95M ops/s (median)
- Improvement: +3.35% mean, +3.36% median
Decision: GO (+3.35% >= +1.0% threshold)
- 3rd consecutive success with consolidation/deduplication pattern
- E4-1: +3.51%, E4-2: +21.83%, E5-1: +3.35%
- Health check: PASS (all profiles)
Phase 5 Cumulative:
- E4 Combined: +6.43%
- E5-1: +3.35%
- Estimated total: ~+10%
Deliverables:
- docs/analysis/PHASE5_E5_COMPREHENSIVE_ANALYSIS.md
- docs/analysis/PHASE5_E5_1_FREE_TINY_DIRECT_1_DESIGN.md
- docs/analysis/PHASE5_E5_1_FREE_TINY_DIRECT_1_AB_TEST_RESULTS.md
- CURRENT_TASK.md (E5-1 complete)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 05:52:32 +09:00
5528612f2a
Phase 5 E4-2: Malloc Wrapper ENV Snapshot (+21.83% GO, ADOPTED)
...
Target: Consolidate malloc wrapper TLS reads + eliminate function calls
- malloc (16.13%) + tiny_alloc_gate_fast (19.50%) = 35.63% combined
- Strategy: E4-1 success pattern + function call elimination
Implementation:
- ENV gate: HAKMEM_MALLOC_WRAPPER_ENV_SNAPSHOT=0/1 (default 0)
- core/box/malloc_wrapper_env_snapshot_box.{h,c}: New box
- Consolidates multiple TLS reads → 1 TLS read
- Pre-caches tiny_max_size() == 256 (eliminates function call)
- Lazy init with probe window (bench_profile putenv sync)
- core/box/hak_wrappers.inc.h: Integration in malloc() wrapper
- Makefile: Add malloc_wrapper_env_snapshot_box.o to all targets
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (SNAPSHOT=0): 35.74M ops/s (mean), 35.75M ops/s (median)
- Optimized (SNAPSHOT=1): 43.54M ops/s (mean), 43.92M ops/s (median)
- Improvement: +21.83% mean, +22.86% median (+7.80M ops/s)
Decision: GO (+21.83% >> +1.0% threshold, 21.8x over)
- Why 6.2x better than E4-1 (+3.51%)?
- Higher malloc call frequency (allocation-heavy workload)
- Function call elimination (tiny_max_size pre-cached)
- Larger target: 35.63% vs free's 25.26%
- Health check: PASS (all profiles)
- Action: PROMOTED to MIXED_TINYV3_C7_SAFE preset
Phase 5 Cumulative (estimated):
- E1 (ENV Snapshot): +3.92%
- E4-1 (Free Wrapper Snapshot): +3.51%
- E4-2 (Malloc Wrapper Snapshot): +21.83%
- Estimated combined: ~+30% (needs validation)
Next Steps:
- Combined A/B test (E4-1 + E4-2 simultaneously)
- Measure actual cumulative effect
- Profile new baseline for next optimization targets
Deliverables:
- docs/analysis/PHASE5_E4_2_MALLOC_WRAPPER_ENV_SNAPSHOT_1_DESIGN.md
- docs/analysis/PHASE5_E4_2_MALLOC_WRAPPER_ENV_SNAPSHOT_1_AB_TEST_RESULTS.md
- docs/analysis/PHASE5_E4_2_MALLOC_WRAPPER_ENV_SNAPSHOT_NEXT_INSTRUCTIONS.md
- docs/analysis/PHASE5_E4_COMBINED_AB_TEST_NEXT_INSTRUCTIONS.md (next)
- docs/analysis/ENV_PROFILE_PRESETS.md (E4-2 added)
- CURRENT_TASK.md (E4-2 complete)
- core/bench_profile.h (E4-2 promoted to default)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 05:13:29 +09:00
4a070d8a14
Phase 5 E4-1: Free Wrapper ENV Snapshot (+3.51% GO, ADOPTED)
...
Target: Consolidate free wrapper TLS reads (2→1)
- free() is 25.26% self% (top hot spot)
- Strategy: Apply E1 success pattern (ENV snapshot) to free path
Implementation:
- ENV gate: HAKMEM_FREE_WRAPPER_ENV_SNAPSHOT=0/1 (default 0)
- core/box/free_wrapper_env_snapshot_box.{h,c}: New box
- Consolidates 2 TLS reads → 1 TLS read (50% reduction)
- Reduces 4 branches → 3 branches (25% reduction)
- Lazy init with probe window (bench_profile putenv sync)
- core/box/hak_wrappers.inc.h: Integration in free() wrapper
- Makefile: Add free_wrapper_env_snapshot_box.o to all targets
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (SNAPSHOT=0): 45.35M ops/s (mean), 45.31M ops/s (median)
- Optimized (SNAPSHOT=1): 46.94M ops/s (mean), 47.15M ops/s (median)
- Improvement: +3.51% mean, +4.07% median
Decision: GO (+3.51% >= +1.0% threshold)
- Exceeded conservative estimate (+1.5% → +3.51%)
- Similar efficiency to E1 (+3.92%)
- Health check: PASS (all profiles)
- Action: PROMOTED to MIXED_TINYV3_C7_SAFE preset
Phase 5 Cumulative:
- E1 (ENV Snapshot): +3.92%
- E4-1 (Free Wrapper Snapshot): +3.51%
- Total Phase 4-5: ~+7.5%
E3-4 Correction:
- Phase 4 E3-4 (ENV Constructor Init): NO-GO / FROZEN
- Initial A/B showed +4.75%, but investigation revealed:
- Branch prediction hint mismatch (UNLIKELY with always-true)
- Retest confirmed -1.78% regression
- Root cause: __builtin_expect(..., 0) with ctor_mode==1
- Decision: Freeze as research box (default OFF)
- Learning: Branch hints need careful tuning, TLS consolidation safer
Deliverables:
- docs/analysis/PHASE5_E4_FREE_GATE_OPTIMIZATION_1_DESIGN.md
- docs/analysis/PHASE5_E4_1_FREE_WRAPPER_ENV_SNAPSHOT_NEXT_INSTRUCTIONS.md
- docs/analysis/PHASE5_E4_2_MALLOC_WRAPPER_ENV_SNAPSHOT_NEXT_INSTRUCTIONS.md (next)
- docs/analysis/PHASE5_POST_E1_NEXT_INSTRUCTIONS.md
- docs/analysis/ENV_PROFILE_PRESETS.md (E4-1 added, E3-4 corrected)
- CURRENT_TASK.md (E4-1 complete, E3-4 frozen)
- core/bench_profile.h (E4-1 promoted to default)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 04:24:34 +09:00
21e2e4ac2b
Phase 4 E3-4: ENV Constructor Init (+4.75% GO)
...
Target: Eliminate E1 lazy init check overhead (3.22% self%)
- E1 consolidated ENV gates but lazy check remained in hot path
- Strategy: __attribute__((constructor(101))) for pre-main init
Implementation:
- ENV gate: HAKMEM_ENV_SNAPSHOT_CTOR=0/1 (default 0, research box)
- core/box/hakmem_env_snapshot_box.c: Constructor function added
- Reads ENV before main() when CTOR=1
- Refresh also syncs gate state for bench_profile putenv
- core/box/hakmem_env_snapshot_box.h: Dual-mode enabled check
- CTOR=1 fast path: direct global read (no lazy branch)
- CTOR=0 fallback: legacy lazy init (rollback safe)
- Branch hints adjusted for default OFF baseline
A/B Test Results (Mixed, 10-run, 20M iters, E1=1):
- Baseline (CTOR=0): 44.28M ops/s (mean), 44.60M ops/s (median)
- Optimized (CTOR=1): 46.38M ops/s (mean), 46.53M ops/s (median)
- Improvement: +4.75% mean, +4.35% median
Decision: GO (+4.75% >> +0.5% threshold)
- Expected +0.5-1.5%, achieved +4.75%
- Lazy init branch overhead was larger than expected
- Action: Keep as research box (default OFF), evaluate promotion
Phase 4 Cumulative:
- E1 (ENV Snapshot): +3.92%
- E2 (Alloc Per-Class): -0.21% (NEUTRAL, frozen)
- E3-4 (Constructor Init): +4.75%
- Total Phase 4: ~+8.5%
Deliverables:
- docs/analysis/PHASE4_E3_ENV_CONSTRUCTOR_INIT_DESIGN.md
- docs/analysis/PHASE4_E3_ENV_CONSTRUCTOR_INIT_NEXT_INSTRUCTIONS.md
- docs/analysis/PHASE4_COMPREHENSIVE_STATUS_ANALYSIS.md
- docs/analysis/PHASE4_EXECUTIVE_SUMMARY.md
- scripts/verify_health_profiles.sh (sanity check script)
- CURRENT_TASK.md (E3-4 complete, next instructions)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-14 02:57:35 +09:00
88717a8737
Phase 4 E1: ENV Snapshot Consolidation - GO (+3.92% avg, +4.01% median)
...
Target: Consolidate 3 ENV gate TLS reads → 1 TLS read
- tiny_c7_ultra_enabled_env(): 1.28% self
- tiny_front_v3_enabled(): 1.01% self
- tiny_metadata_cache_enabled(): 0.97% self
- Total overhead: 3.26% self (perf profile analysis)
Implementation:
- core/box/hakmem_env_snapshot_box.h (new): ENV snapshot struct & API
- core/box/hakmem_env_snapshot_box.c (new): TLS snapshot implementation
- core/front/malloc_tiny_fast.h: Migrated 5 call sites to snapshot
- core/box/tiny_legacy_fallback_box.h: Migrated 2 call sites
- core/box/tiny_metadata_cache_hot_box.h: Migrated 1 call site
- core/bench_profile.h: Added hakmem_env_snapshot_refresh_from_env()
- Makefile: Added hakmem_env_snapshot_box.o to build
- ENV gate: HAKMEM_ENV_SNAPSHOT=0/1 (default: 0, research box)
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (E1=0): 43,617,549 ops/s (avg), 43,562,895 ops/s (median)
- Optimized (E1=1): 45,327,239 ops/s (avg), 45,309,218 ops/s (median)
- Improvement: avg +3.92%, median +4.01%
Decision: GO (+3.92% >= +2.5% threshold)
- Action: Keep as research box (default OFF) for Phase 4
- Next: Consider promotion to default in MIXED_TINYV3_C7_SAFE preset
Design Rationale:
- Shape optimizations (B3, D3) reached saturation (+0.56% NEUTRAL)
- Shift to memory/TLS overhead optimization (new optimization frontier)
- Pattern: Similar to existing tiny_front_v3_snapshot (proven approach)
- Expected: +1-3% from 3.26% ENV overhead → Achieved: +3.92%
Technical Details:
- Consolidation: 3 TLS reads → 1 TLS read (66% reduction)
- Learner interlock: tiny_metadata_cache_eff pre-computed in snapshot
- Version sync: Refreshes on small_policy_v7_version_changed()
- Fallback safety: Existing ENV gates still available when E1=0
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-14 00:59:12 +09:00
11b0e3f32b
Phase 4 D3: alloc gate shape (env-gated)
2025-12-14 00:26:57 +09:00
19056282b6
Phase 3 D2: Wrapper Env Cache - [DECISION: NO-GO]
...
Target: Reduce wrapper_env_cfg() overhead in malloc/free hot path
- Strategy: Cache wrapper env configuration pointer in TLS
- Approach: Fast pointer cache (TLS caches const wrapper_env_cfg_t*)
Implementation:
- core/box/wrapper_env_cache_env_box.h: ENV gate (HAKMEM_WRAP_ENV_CACHE)
- core/box/wrapper_env_cache_box.h: TLS cache layer (wrapper_env_cfg_fast)
- core/box/hak_wrappers.inc.h: Integration into malloc/free hot paths
- ENV gate: HAKMEM_WRAP_ENV_CACHE=0/1 (default OFF)
A/B Test Results (Mixed, 10-run, 20M iters):
- Baseline (D2=0): 46.52M ops/s (avg), 46.47M ops/s (median)
- Optimized (D2=1): 45.85M ops/s (avg), 45.98M ops/s (median)
- Improvement: avg -1.44%, median -1.05% (DECISION: NO-GO)
Analysis:
- Regression cause: TLS cache adds overhead (branch + TLS access)
- wrapper_env_cfg() is already minimal (pointer return after simple check)
- Adding TLS caching layer makes it worse, not better
- Branch prediction penalty outweighs any potential savings
Cumulative Phase 2-3:
- B3: +2.89%, B4: +1.47%, C3: +2.20%
- D1: +1.06% (opt-in), D2: -1.44% (NO-GO)
- Total: ~7.2% (excluding D2)
Decision: FREEZE as research box (default OFF, regression confirmed)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 22:03:27 +09:00
f059c0ec83
Phase 3 D1: Free Path Route Cache - DECISION: GO (+1.06%)
...
Target: Eliminate tiny_route_for_class() overhead in free path
- Perf finding: 4.39% self + 24.78% children (free bottleneck)
- Approach: Use cached route_kind (like Phase 3 C3 for alloc)
Implementation:
- core/box/tiny_free_route_cache_env_box.h (new)
* ENV gate: HAKMEM_FREE_STATIC_ROUTE=0/1 (default OFF)
* Lazy initialization with sentinel value
- core/front/malloc_tiny_fast.h (modified)
* Two call sites: free_tiny_fast_cold() + legacy_fallback path
* Direct route lookup: g_tiny_route_class[class_idx]
* Fallback safety: Check g_tiny_route_snapshot_done
A/B Test Results (Mixed, 10-run):
- Baseline (D1=0): 45.13 M ops/s (avg), 45.76 M ops/s (median)
- Optimized (D1=1): 45.61 M ops/s (avg), 45.40 M ops/s (median)
- Improvement: +1.06% (avg), -0.77% (median)
- DECISION: GO (avg gain meets +1.0% threshold)
Cumulative Phase 2-3:
- B3: +2.89%, B4: +1.47%, C3: +2.20%
- D1: +1.06%
- Total: ~7.2% cumulative gain
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 21:44:00 +09:00
deecda7336
Phase 3 C2: Slab Metadata Cache Optimization (3 patches) - NEUTRAL
...
Patch 1: Policy Hot Cache
- Add TinyPolicyHot struct (route_kind[8] cached in TLS)
- Eliminate policy_snapshot() calls (~2 memory ops saved)
- Safety: disabled when learner v7 active
- Files: tiny_metadata_cache_env_box.h, tiny_metadata_cache_hot_box.{h,c}
- Integration: malloc_tiny_fast.h route selection
Patch 2: First Page Inline Cache
- Cache current slab page pointer in TLS per-class
- Avoid superslab metadata lookup (1-2 memory ops)
- Fast-path in tiny_legacy_fallback_free_base()
- Files: tiny_first_page_cache.h, tiny_unified_cache.c
- Integration: tiny_legacy_fallback_box.h
Patch 3: Bounds Check Compile-out
- Hardcode unified_cache capacity as MACRO constant
- Eliminate modulo operation (constant fold)
- Macros: TINY_UNIFIED_CACHE_CAPACITY_POW2=11, CAPACITY=2048, MASK=2047
- File: tiny_unified_cache.h
A/B Test Results (Mixed, 10-run):
- Baseline (C2=0): 40.43M ops/s (avg), 40.72M ops/s (median)
- Optimized (C2=1): 40.25M ops/s (avg), 40.29M ops/s (median)
- Improvement: -0.45% (avg), -1.06% (median)
- DECISION: NEUTRAL (within ±1.0% threshold)
- Action: Keep as research box (ENV gate OFF by default)
Cumulative Gain (Phase 2-3):
- B3 (Routing shape): +2.89%
- B4 (Wrapper split): +1.47%
- C3 (Static routing): +2.20%
- C2 (Metadata cache): -0.45%
- Total: ~6.1% (from baseline 37.5M → 39.8M ops/s)
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 19:19:42 +09:00
d0b931b197
Phase 3 C1: TLS Prefetch Implementation - NEUTRAL Result (Research Box)
...
Step 1 & 2 Complete:
- Implemented: core/front/malloc_tiny_fast.h prefetch (lines 264-267, 331-334)
- LEGACY path prefetch of g_unified_cache[class_idx] to L1
- ENV gate: HAKMEM_TINY_PREFETCH=0/1 (default OFF)
- Conditional: only when prefetch enabled + route_kind == LEGACY
- A/B test (Mixed 10-run): PREFETCH=0 (39.33M) → =1 (39.20M) = -0.34% avg
- Median: +1.28% (within ±1.0% neutral range)
- Result: 🔬 NEUTRAL (research box, default OFF)
Decision: FREEZE as research box
- Average -0.34% suggests prefetch overhead > benefit
- Prefetch timing too late (after route_kind selection)
- TLS cache access is already fast (head/tail indices)
- Actual memory wait happens at slots[] array access (after prefetch)
Technical Learning:
- Prefetch effectiveness depends on L1 miss rate at access time
- Inserting prefetch after route selection may be too late
- Future approach: move prefetch earlier or use different target
Next: Phase 3 C2 (Metadata Cache Optimization, expected +5-10%)
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 19:01:57 +09:00
d54893ea1d
Phase 3 C3: Static Routing A/B Test ADOPT (+2.20% Mixed gain)
...
Step 2 & 3 Complete:
- A/B test (Mixed 10-run): STATIC_ROUTE=0 (38.91M) → =1 (39.77M) = +2.20% avg
- Median gain: +1.98%
- Result: ✅ GO (exceeds +1.0% threshold)
- Decision: ✅ ADOPT into MIXED_TINYV3_C7_SAFE preset
- bench_profile.h line 77: HAKMEM_TINY_STATIC_ROUTE=1 default
- Learner auto-disables static route when HAKMEM_SMALL_LEARNER_V7_ENABLED=1
Implementation Summary:
- core/box/tiny_static_route_box.{h,c}: Research box (Step 1A)
- core/front/malloc_tiny_fast.h: Route lookup integration (Step 1B, lines 249-256)
- core/bench_profile.h: Bench sync + preset adoption
Cumulative Phase 2-3 Gains:
- B3 (Routing shape): +2.89%
- B4 (Wrapper split): +1.47%
- C3 (Static routing): +2.20%
- Total: ~6.8% (35.2M → ~39.8M ops/s)
Next: Phase 3 C1 (TLS Prefetch, expected +2-4%)
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 18:46:11 +09:00
1798ed656d
Phase 3 C3: Tiny Static Routing Box Implementation (Step 1A)
...
Research Box Implementation:
- core/box/tiny_static_route_box.h: TinyStaticRoute struct & API
- core/box/tiny_static_route_box.c: Static route table management
- Makefile: Added tiny_static_route_box.o to 3 OBJS lists
Design:
- ENV gate: HAKMEM_TINY_STATIC_ROUTE=0/1 (default: 0)
- Learner auto-disable: If HAKMEM_TINY_LEARNER_ENABLED=1, force OFF
- Constructor priority: 102 (runs after wrapper_env_ctor at 101)
- Thread-safe: Atomic CAS for exactly-once initialization
Baseline Profiling (Step 0 Complete):
- Throughput: 46.2M ops/s (10M iterations × 400 ws)
- Instructions/cycle: 2.11 insn/cycle
- Frontend stalls: 10.62% (memory latency bottleneck)
- Cache-misses: 3.46% of references
Expected C3 gain: +5-8% (policy_snapshot bypass)
Next Steps (Step 1B onwards):
1. Integrate static route into malloc_tiny_fast_for_class()
2. A/B test: Mixed 10-run, expect +1% minimum for GO
3. Decision: GO if +1%, NO-GO if -1%, else freeze
Status:
✅ Phase 2 (B3+B4): +4.4% cumulative
✅ Phase 3 planning & C3 Step 0-1A complete
⏳ Phase 3 C3 Step 1B-3 pending (malloc integration & testing)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 18:04:14 +09:00
c687673a99
Phase 2 B4: Wrapper Layer Hot/Cold Split (malloc/free) - ADOPT (+1.47%)
...
- Implement malloc_cold() helper (noinline,cold) for LD mode, jemalloc, force_libc
- Add malloc() hot/cold dispatch with HAKMEM_WRAP_SHAPE=1 ENV gate
- Implement free_cold() helper (noinline,cold) for classification, ownership checks
- Add free() hot/cold dispatch: hot path returns early, cold path delegates to free_cold()
- Lock_depth symmetry verified on all return paths (malloc: ++/--, free: consistent)
A/B Testing Results (Mixed 10-run):
WRAP_SHAPE=0 (default): 34,750,578 ops/s
WRAP_SHAPE=1 (optimized): 35,262,596 ops/s
Average gain: +1.47% (Median: +1.39%)
✓ Decision: GO (exceeds +1.0% threshold)
Implementation Strategy:
- Separate frequently-executed code from rare paths (LD, jemalloc, diagnostics)
- Keep hot path instruction count minimal (returns early on success)
- L1 I-cache pressure reduction via noinline,cold attributes
- Default OFF (HAKMEM_WRAP_SHAPE=0) maintains backward compatibility
Files:
- core/box/hak_wrappers.inc.h: malloc_cold(), free_cold(), hot/cold dispatches
- core/box/wrapper_env_box.h/c: HAKMEM_WRAP_SHAPE ENV variable caching
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 17:08:24 +09:00
0feeccdcef
Phase 2 B1/B3/B4 preparation: Analysis & ENV gate setup
...
## Phase 2 Optimization Research Complete
### B1 (Header tax reduction v2) - NO-GO
- HAKMEM_TINY_HEADER_MODE=LIGHT: -2.54% regression on Mixed
- Decision: FREEZE as research box (ENV opt-in only)
### B3 (Routing branch shape optimization) - ADOPT
- Mixed: +2.89% (48.41M → 49.80M ops/s)
- C6-heavy: +9.13% (8.97M → 9.79M ops/s)
- Strategy: LIKELY on LEGACY (hot), noinline,cold helper for rare routes
- Implementation: Already in malloc_tiny_fast.h:252-267
- Profile updates: HAKMEM_TINY_ALLOC_ROUTE_SHAPE=1 now default
### B4 (Wrapper Layer Hot/Cold Split) - Preparation
- Design memo: docs/analysis/PHASE2_B4_WRAPPER_SHAPE_1_DESIGN.md
- Goal: Split malloc/free into hot/cold paths, reduce I-cache pressure
- ENV gate: HAKMEM_WRAP_SHAPE=0/1 (added to wrapper_env_box)
- Expected gain: +2-5% Mixed, +1-3% C6-heavy
## Analysis Summary
- Background is visible: FREE DUALHOT + B3 routing optimizations work
- Code layering is clean: winning boxes promoted to presets, losing boxes frozen with ENV guards
- Remaining gap to mimalloc is wrapper layer + safety checks + policy snapshot
- Further +5-10% still realistically achievable
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 16:46:18 +09:00
df37baa505
Phase 1A3: tiny_region_id_write_header always_inline research box (NO-GO)
...
Add HAKMEM_TINY_HEADER_WRITE_ALWAYS_INLINE build flag (default 0) to enable
always_inline on tiny_region_id_write_header().
A/B Results (HAKMEM_TINY_HEADER_WRITE_ALWAYS_INLINE=0 vs 1):
- Mixed (10-run): 49.53M → 47.55M ops/s (-4.00% regression)
- C6-heavy (5-run): 23.49M → 24.93M ops/s (+6.00% improvement)
Decision: NO-GO - Mixed regression (-4%) exceeds threshold (-1%)
Status: Frozen as research box (default OFF)
Root Cause: I-cache pressure from forced inline expansion
- Mixed workload: higher code diversity → I-cache evictions
- C6-heavy workload: focused pattern → benefits from inlining
Patches:
1. core/hakmem_build_flags.h: Add HAKMEM_TINY_HEADER_WRITE_ALWAYS_INLINE (default 0)
2. core/tiny_region_id.h: Add conditional __attribute__((always_inline)) gate
Build: make -j EXTRA_CFLAGS=-DHAKMEM_TINY_HEADER_WRITE_ALWAYS_INLINE=1 [target]
Recommendation: Keep compiler's natural inline heuristic (already optimal for Mixed)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 15:31:08 +09:00
d0f939c2eb
Phase ALLOC-GATE-SSOT-1 + ALLOC-TINY-FAST-DUALHOT-2: Structure fixes for alloc path
...
4 patches to eliminate allocation overhead and enable research path:
Patch 1: Extract malloc_tiny_fast_for_class(size, class_idx)
- SSOT: size→class conversion happens once in gate
- malloc_tiny_fast() becomes thin wrapper
- Foundation for eliminating duplicate lookups
Patch 2: Update tiny_alloc_gate_fast() to call *_for_class
- Pass class_idx computed in gate to malloc_tiny_fast_for_class()
- Eliminates second hak_tiny_size_to_class() call
- Impact: +1-2% expected from reduced instruction count
Patch 3: Reposition DUALHOT branch (C0-C3 only)
- Move class_idx <= 3 check outside alloc_dualhot_enabled()
- C4-C7 no longer evaluate ENV gate (even when OFF)
- Impact: Maintains neutral performance on default path
Patch 4: Probe window for ENV gate
- Tolerate early putenv() before probe window exhausted (64 calls)
- Maintains correctness for bench_profile setenv timing
A/B Results (DUALHOT=0 vs DUALHOT=1):
- Mixed median: 48.75M → 48.62M ops/s (-0.27%, neutral within variance)
- C6-heavy median: 23.24M → 23.63M ops/s (+1.68%, SSOT benefit)
Decision: ADOPT with DUALHOT default OFF (research feature)
- SSOT provides structural improvement
- No regression on default configuration
- C6-heavy shows SSOT effectiveness (+1.68%)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 06:50:39 +09:00
d9991f39ff
Phase ALLOC-TINY-FAST-DUALHOT-1 & Optimization Roadmap Update
...
Add comprehensive design docs and research boxes:
- docs/analysis/ALLOC_TINY_FAST_DUALHOT_1_DESIGN.md: ALLOC DUALHOT investigation
- docs/analysis/FREE_TINY_FAST_DUALHOT_1_DESIGN.md: FREE DUALHOT final specs
- docs/analysis/FREE_TINY_FAST_HOTCOLD_OPT_1_DESIGN.md: Hot/Cold split research
- docs/analysis/POOL_MID_INUSE_DEFERRED_DN_BATCH_DESIGN.md: Deferred batching design
- docs/analysis/POOL_MID_INUSE_DEFERRED_REGRESSION_ANALYSIS.md: Stats overhead findings
- docs/analysis/MID_DESC_CACHE_BENCHMARK_2025-12-12.md: Cache measurement results
- docs/analysis/LAST_MATCH_CACHE_IMPLEMENTATION.md: TLS cache investigation
Research boxes (SS page table):
- core/box/ss_pt_env_box.h: HAKMEM_SS_LOOKUP_KIND gate
- core/box/ss_pt_types_box.h: 2-level page table structures
- core/box/ss_pt_lookup_box.h: ss_pt_lookup() implementation
- core/box/ss_pt_register_box.h: Page table registration
- core/box/ss_pt_impl.c: Global definitions
Updates:
- docs/specs/ENV_VARS_COMPLETE.md: HOTCOLD, DEFERRED, SS_LOOKUP env vars
- core/box/hak_free_api.inc.h: FREE-DISPATCH-SSOT integration
- core/box/pool_mid_inuse_deferred_box.h: Deferred API updates
- core/box/pool_mid_inuse_deferred_stats_box.h: Stats collection
- core/hakmem_super_registry: SS page table integration
Current Status:
- FREE-TINY-FAST-DUALHOT-1: +13% improvement, ready for adoption
- ALLOC-TINY-FAST-DUALHOT-1: -2% regression, frozen as research box
- Next: Optimization roadmap per ROI (mimalloc gap 2.5x)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-13 05:35:46 +09:00
b2724e6f5d
Phase ALLOC-TINY-FAST-DUALHOT-1: WIP (regression), FREE DUALHOT confirmed +13%
...
**ALLOC-TINY-FAST-DUALHOT-1** (this phase):
- Implementation: malloc_tiny_fast() C0-C3 early-exit with policy snapshot skip
- ENV: HAKMEM_TINY_ALLOC_DUALHOT=0/1 (default OFF)
- A/B Result: -1.17% median regression (Mixed, 10-run)
- Root Cause: Branch prediction penalty on C4-C7 outweighs policy skip benefit
- Decision: Freeze as research box (default OFF)
- Difference from FREE: ALLOC requires structural changes (per-class paths)
**FREE-TINY-FAST-DUALHOT-1** (verified):
- A/B Confirmation: +13.00% improvement (42.08M → 47.81M ops/s, Mixed, 10-run)
- Success Criteria: +2% target ACHIEVED
- Health Check: PASS (verify_health_profiles.sh, ENV OFF/ON)
- Safety: HAKMEM_TINY_LARSON_FIX guard in place
- Decision: Promotion to MIXED_TINYV3_C7_SAFE profile candidate
**Next Steps**:
- Profile adoption of FREE DUALHOT for MIXED workload
- No further deep-dive on ALLOC optimization (deferred to future phases)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-13 05:10:45 +09:00
0a7400d7d3
Phase ALLOC-TINY-FAST-DUALHOT-1: C0-C3 alloc direct path (WIP, -2% regression)
...
Add C0-C3 early-exit optimization to malloc_tiny_fast() similar to
FREE-TINY-FAST-DUALHOT-1. Skip policy snapshot for C0-C3 classes.
A/B Result (10-run, Mixed TINYV3_C7_SAFE):
- Baseline: 47.27M ops/s (median)
- Optimized: 46.10M ops/s (median)
- Result: -2.00% (regression, needs investigation)
ENV: HAKMEM_TINY_ALLOC_DUALHOT=0/1 (default OFF)
Implementation:
- core/front/malloc_tiny_fast.h: alloc_dualhot_enabled() + early-exit
- Design: docs/analysis/ALLOC_TINY_FAST_DUALHOT_1_DESIGN.md
Status: Research box (default OFF), needs root cause analysis
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-13 04:28:52 +09:00
2b567ac070
Phase FREE-TINY-FAST-DUALHOT-1: Optimize C0-C3 direct free path
...
Treat C0-C3 classes (48% of calls) as "second hot path" instead of
cold path. Skip expensive policy snapshot and route determination,
direct to tiny_legacy_fallback_free_base().
Measurements from FREE-TINY-FAST-HOTCOLD-OPT-1 revealed C0-C3 is NOT
rare (48.43% of all frees). Previous attempt to optimize via hot/cold
split failed (-13% regression) because noinline + function call on 48%
of workload hurt more than it helped.
This phase applies correct optimization: direct inline path for
frequent C0-C3 without policy snapshot overhead.
Implementation:
- Insert C0-C3 early-exit after C7 ULTRA check
- Skip tiny_front_v3_snapshot_get() for C0-C3 (saves 5-10 cycles)
- Skip route determination logic
- Safety: HAKMEM_TINY_LARSON_FIX=1 disables optimization
Benchmark Results (100M ops, 400 threads, MIXED_TINYV3_C7_SAFE):
- Baseline (optimization OFF): 44.50M ops/s (median)
- Optimized (DUALHOT ON): 48.74M ops/s (median)
- Improvement: +9.51% (+4.23M ops/s)
Perf Stats (optimized):
- Branch misses: 112.8M
- Cycles: 8.89B
- Instructions: 21.95B (2.47 IPC)
- Cache misses: 656K
Status: GO (significant improvement, no regression)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 03:46:36 +09:00
c503b212a3
Phase FREE-TINY-FAST-HOTCOLD-OPT-1: Hot/Cold split for free_tiny_fast [RESEARCH BOX - FREEZE]
...
Split free_tiny_fast() into hot and cold paths to reduce I-cache pressure:
- free_tiny_fast_hot(): always_inline, fast-path validation + ULTRA/MID/V7
- free_tiny_fast_cold(): noinline,cold, cross-thread + TinyHeap + legacy
ENV: HAKMEM_FREE_TINY_FAST_HOTCOLD=0/1 (default 0)
Stats: HAKMEM_FREE_TINY_FAST_HOTCOLD_STATS=0/1 (TLS only, exit dump)
## Benchmark Results (random mixed, 100M ops)
HOTCOLD=0 (legacy): 49.35M, 50.18M, 50.25M ops/s (median: 50.18M)
HOTCOLD=1 (split): 43.54M, 43.59M, 43.62M ops/s (median: 43.59M)
**Regression: -13.1%** (NO-GO)
## Stats Analysis (10M ops, HOTCOLD_STATS=1)
Hot path: 50.11% (C7 ULTRA early-exit)
Cold path: 48.43% (legacy fallback)
## Root Cause
Design assumption FAILED: "Cold path is rare"
Reality: Cold path is 48% (almost as common as hot path)
The split introduces:
1. Extra dispatch overhead in hot path
2. Function call overhead to cold for ~48% of frees
3. "Cold" is NOT rare - it's the legacy fallback for non-ULTRA classes
## Conclusion
**FREEZE as research box (default OFF)**
Box Theory value:
- Validated hot/cold distribution via TLS stats
- Confirmed that legacy fallback is NOT rare (48%)
- Demonstrated that naive hot/cold split hurts when "cold" is common
Alternative approaches for future work:
1. Inline the legacy fallback in hot path (no split)
2. Route-specific specialization (C7 vs non-C7 separate paths)
3. Policy-based early routing (before header validation)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-13 03:16:54 +09:00
4e7870469c
POOL-MID-DN-BATCH: Add hash-based TLS page map (O(1) lookup)
...
Replace linear search (avg 16 iterations, -7.6% regression) with
open addressing hash table:
- Size: 64 slots (power-of-two)
- Collision: Linear probing, max 8 probes
- On probe limit: drain and retry (safe fallback)
- Hash function: Golden ratio with page-aligned shift
New ENV: HAKMEM_POOL_MID_INUSE_MAP_KIND=hash|linear (default: linear)
Implementation:
- Added hak_pool_mid_inuse_map_hash_enabled() ENV gate
- Extended MidInuseTlsPageMap with hash_pages[64], hash_counts[64], hash_used
- Added mid_inuse_hash_page() golden ratio hash function
- Added mid_inuse_dec_deferred_hash() O(1) insert with probing
- Updated mid_inuse_deferred_drain() to support hash mode
- Added decs_drained stats counter for batching metrics
Benchmark Results (10 runs each, bench_mid_large_mt_hakmem):
Baseline (DEFERRED=0): median=9,250,340 ops/s
Linear mode: median=8,159,240 ops/s (-11.80%)
Hash mode: median=8,262,982 ops/s (-10.67%)
Hash vs Linear: +1.27% improvement (eliminates linear search overhead)
Note: Both deferred modes still show regression vs baseline due to
other factors (TLS access overhead, drain cost). Hash mode successfully
eliminates the linear search penalty as designed.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-13 00:28:03 +09:00
6c849fd020
POOL-MID-DN-BATCH: Add last-match cache to reduce linear search overhead
...
Root cause: Linear search in 32-entry TLS map averaged 16 iterations,
causing instruction overhead that exceeded mid_desc_lookup savings.
Fix implemented:
- Added last_idx field to MidInuseTlsPageMap for temporal locality
- Check last_idx before linear search (O(1) fast path)
- Update last_idx on hits and new entries
- Reset last_idx on drain
Changes:
1. pool_mid_inuse_tls_pagemap_box.h:
- Added uint32_t last_idx field to struct
2. pool_mid_inuse_deferred_box.h:
- Check last_idx before linear search (lines 90-94)
- Update last_idx on linear search hit (line 101)
- Set last_idx on new entry insert (line 117)
- Reset last_idx on drain (line 166)
Benchmark results (bench_mid_large_mt_hakmem):
- Baseline (DEFERRED=0): median 9.08M ops/s, variance 300B
- Deferred with cache (DEFERRED=1): median 8.38M ops/s, variance 207B
- Performance: -7.6% regression (vs expected +2-4% gain)
- Stability: -31% variance (improvement as expected)
Analysis:
The last-match cache reduces variance but does not eliminate the
regression for this benchmark's random access pattern (2048 slots,
many pages). The temporal locality assumption (60-80% hit rate) is
not met by bench_mid_large_mt's allocation pattern.
Further optimization needed:
- Consider hash-based lookup for better than O(n) search
- OR reduce map size to decrease search iterations
- OR add drain triggers at better boundaries
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-13 00:04:41 +09:00
16b415f5a2
Phase POOL-MID-DN-BATCH Step 5: Integrate deferred API into pool_free_v1
2025-12-12 23:00:06 +09:00
cba444b943
Phase POOL-MID-DN-BATCH Step 4: Deferred API implementation with thread cleanup
2025-12-12 23:00:00 +09:00
d45729f063
Phase POOL-MID-DN-BATCH Step 3: Statistics counters for deferred inuse_dec
2025-12-12 22:59:56 +09:00
b381515b16
Phase POOL-MID-DN-BATCH Step 2: TLS page map for batched inuse_dec
2025-12-12 22:59:50 +09:00
f5f03ef68c
Phase POOL-MID-DN-BATCH Step 1: ENV gate for deferred inuse_dec
2025-12-12 22:59:45 +09:00
506d8f2e5e
Phase: Pool API Modularization - Step 8 (FINAL): Extract pool_alloc_v1_box.h
...
Extract 288 lines: hak_pool_try_alloc_v1_impl() - LARGEST SIZE
- New box: core/box/pool_alloc_v1_box.h (v1 alloc baseline, no hotbox_v2)
- Updated: pool_api.inc.h (add include, remove extracted function)
- Build: OK, bench_mid_large_mt_hakmem: 8.01M ops/s (baseline ~8M, within ±2%)
- Risk: MEDIUM (simpler than v2 but large function, validated)
- Result: pool_api.inc.h reduced from 909 lines to ~40 lines (95% reduction)
ALL 5 STEPS COMPLETE (Steps 4-8):
- Step 4: pool_block_to_user_box.h (30 lines) - helpers
- Step 5: pool_free_v2_box.h (121 lines) - v2 free with hotbox
- Step 6: pool_alloc_v1_flat_box.h (103 lines) - v1 flatten TLS
- Step 7: pool_alloc_v2_box.h (277 lines) - v2 alloc with hotbox
- Step 8: pool_alloc_v1_box.h (288 lines) - v1 alloc baseline
Total extracted: 819 lines
Final pool_api.inc.h size: ~40 lines (public wrappers only)
Performance: MAINTAINED (8M ops/s baseline)
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 22:28:13 +09:00
76a5bb568a
Phase: Pool API Modularization - Step 7: Extract pool_alloc_v2_box.h
...
Extract 277 lines: hak_pool_try_alloc_v2_impl() - LARGEST COMPLEXITY
- New box: core/box/pool_alloc_v2_box.h (v2 alloc with hotbox, MF2, TC drain, TLS)
- Updated: pool_api.inc.h (add include, remove extracted function)
- Build: OK, bench_mid_large_mt_hakmem: 8.86M ops/s (baseline ~8M, within ±2%)
- Risk: MEDIUM (complex function with 30+ dependencies, validated)
- Note: Avoided forward declarations for types/macros already in compilation unit
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 22:24:21 +09:00
5f069e08bf
Phase: Pool API Modularization - Step 6: Extract pool_alloc_v1_flat_box.h
...
Extract 103 lines: hak_pool_try_alloc_v1_flat() + hak_pool_free_v1_flat()
- New box: core/box/pool_alloc_v1_flat_box.h (v1 flatten TLS-only fast path)
- Updated: pool_api.inc.h (add include, remove extracted functions)
- Build: OK, bench_mid_large_mt_hakmem: 9.17M ops/s (baseline ~8M, within ±2%)
- Risk: MINIMAL (TLS-only path, well-isolated)
- Note: Added forward declarations for v1_impl functions (defined later)
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 22:20:19 +09:00
0ad9c57aca
Phase: Pool API Modularization - Step 5: Extract pool_free_v2_box.h
...
Extract 121 lines: hak_pool_free_v2_impl() + hak_pool_mid_lookup_v2_impl() + hak_pool_free_fast_v2_impl()
- New box: core/box/pool_free_v2_box.h (v2 free with hotbox support)
- Updated: pool_api.inc.h (add include, remove extracted functions)
- Build: OK, bench_mid_large_mt_hakmem: 8.58M ops/s (baseline ~8M, within ±2%)
- Risk: LOW-MEDIUM (hotbox_v2 integration, well-isolated)
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 22:17:53 +09:00
0da8a63fa5
Phase: Pool API Modularization - Step 4: Extract pool_block_to_user_box.h
...
Extract 30 lines: hak_pool_block_to_user() + hak_pool_block_to_user_legacy()
- New box: core/box/pool_block_to_user_box.h (helpers for block→user conversion)
- Updated: pool_api.inc.h (add include, remove extracted functions)
- Build: OK, bench_mid_large_mt_hakmem: 9.17M ops/s (baseline ~8M)
- Risk: MINIMAL (simple extraction, no dependencies)
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 22:15:21 +09:00
a92f3e52c3
Phase: Pool API Modularization - Step 3: Extract pool_free_v1_box.h
...
Extracted pool v1 free implementation into separate box module:
- hak_pool_free_v1_fast_impl(): L1-FastBox (TLS-only path, no mid_desc_lookup)
- hak_pool_free_v1_slow_impl(): L1-SlowBox (full impl with lookup)
- hak_pool_free_v1_impl(): L0-SplitBox (fast predicate router)
Benefits:
- Reduced pool_api.inc.h from ~950 to ~840 lines
- Clear separation of concern (fast vs slow paths)
- Enables future phase extensions (e.g., POOL-MID-DN-BATCH)
- Maintains zero-cost abstraction (all inline)
Testing:
- Build: ✓ (no errors)
- Benchmark: ✓ (7.99M ops/s, consistent with baseline)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 21:46:26 +09:00
b01c99f209
Phase: Pool API Modularization - Steps 1-2
...
Extract configuration, statistics, and caching boxes from pool_api.inc.h
Step 1: pool_config_box.h (60 lines)
- All ENV gate predicates (hak_pool_v2_enabled, hak_pool_v1_flatten_enabled, etc)
- Lazy static int cache pattern (matches tiny_heap_env_box.h style)
- Zero dependencies (lowest-level box)
Step 2a: pool_stats_box.h (90 lines)
- PoolV1FlattenStats structure with multi-phase support
- pool_v1_flat_stats_dump() with phase-aware output
- Destructor hook for automatic dumping on exit
- Multi-phase design: supports future phases without refactoring
Step 2b: pool_mid_desc_cache_box.h (60 lines)
- MidDescCache structure (TLS-local single-entry LRU)
- mid_desc_lookup_cached() with fast TLS hit path
- Minimal external dependency: mid_desc_lookup from pool_mid_desc.inc.h
Result: pool_api.inc.h reduced from 1050+ lines to ~950 lines
Still contains: alloc/free implementations, helpers (next steps)
Build: ✅ Clean (no warnings)
Test: ✅ Benchmark passes (8.5M ops/s)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-12 21:39:18 +09:00
c86a59159b
Phase POOL-FREE-V1-OPT Step 2: Fast/Slow split for v1 free
...
Implement L0-SplitBox + L1-FastBox/SlowBox architecture for pool v1 free:
L0-SplitBox (hak_pool_free_v1_impl):
- Fast predicate: header-based same-thread detection
- Requires g_hdr_light_enabled == 0, tls_free_enabled
- Routes to fast or slow box based on predicate
L1-FastBox (hak_pool_free_v1_fast_impl):
- Same-thread TLS free path only (ring → lo_head → spill)
- Skips mid_desc_lookup for validation (uses header)
- Still calls mid_page_inuse_dec_and_maybe_dn at end
L1-SlowBox (hak_pool_free_v1_slow_impl):
- Full v1 impl with mid_desc_lookup for validation
- Handles cross-thread, TC lookup, etc.
ENV gate: HAKMEM_POOL_V1_FREE_FASTSPLIT (default OFF)
Stats tracking:
- fastsplit_fast_hit: Fast path taken (>99% typically)
- fastsplit_slow_hit: Slow path taken (predicate failed)
Benchmark result (FLATTEN OFF, Mixed profile):
- Baseline: ~8.3M ops/s (high variance)
- FASTSPLIT ON: ~8.1M ops/s (high variance)
- Performance neutral (savings limited by inuse_dec still calling mid_desc_lookup)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-12 19:52:36 +09:00
dbdd2e0e0e
Phase POOL-FREE-V1-OPT Step 1: Add v2 reject stats tracking
...
Add reject reason counters for v2 free path to understand fallback patterns:
- v2_reject_total: Total v2 free rejects
- v2_reject_ptr_null: ptr == NULL
- v2_reject_not_init: pool not initialized
- v2_reject_desc_null: mid_desc_lookup returned NULL
- v2_reject_mf2_null: MF2 path but mf2_addr_to_page returned NULL
ENV gate: HAKMEM_POOL_FREE_V1_REJECT_STATS (default OFF)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-12 19:43:03 +09:00
fe70e3baf5
Phase MID-V35-HOTPATH-OPT-1 complete: +7.3% on C6-heavy
...
Step 0: Geometry SSOT
- New: core/box/smallobject_mid_v35_geom_box.h (L1/L2 consistency)
- Fix: C6 slots/page 102→128 in L2 (smallobject_cold_iface_mid_v3.c)
- Applied: smallobject_mid_v35.c, smallobject_segment_mid_v3.c
Step 1-3: ENV gates for hotpath optimizations
- New: core/box/mid_v35_hotpath_env_box.h
* HAKMEM_MID_V35_HEADER_PREFILL (default 0)
* HAKMEM_MID_V35_HOT_COUNTS (default 1)
* HAKMEM_MID_V35_C6_FASTPATH (default 0)
- Implementation: smallobject_mid_v35.c
* Header prefill at refill boundary (Step 1)
* Gated alloc_count++ in hot path (Step 2)
* C6 specialized fast path with constant slot_size (Step 3)
A/B Results:
C6-heavy (257–768B): 8.75M→9.39M ops/s (+7.3%, 5-run mean) ✅
Mixed (16–1024B): 9.98M→9.96M ops/s (-0.2%, within noise) ✓
Decision: FROZEN - defaults OFF, C6-heavy推奨ON, Mixed現状維持
Documentation: ENV_PROFILE_PRESETS.md updated
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 19:19:25 +09:00
e95e61f0ff
Phase POLICY-FAST-PATH-V2 complete + MID-V35-HOTPATH-OPT-1 design
...
## Phase POLICY-FAST-PATH-V2 (FROZEN)
- Implementation complete: free_policy_fast_v2_box.h + malloc_tiny_fast.h integration
- A/B Results:
- Mixed (ws=400): -1.6% regression ❌ (branch cost > skip benefit)
- C6-heavy (ws=200): +5.4% improvement ✅
- Decision: Default OFF, FROZEN (ws<300 / C6-heavy research only)
- Learning: Large WS causes branch misprediction to dominate
## Phase 3-GRADUATE + ENV probe fix
- 64-probe retry for getenv() stability during bench_profile putenv()
- C6 ULTRA intrusive freelist: FROZEN (research box)
## Phase MID-V35-HOTPATH-OPT-1-DESIGN
- Design doc for next optimization target
- Target: MID v3.5 alloc/free hot path (C5-C6)
- Boxes: Stats Gate, TLS Layout, Boundary Check elimination
- Expected: +3-9% on Mixed mainline
Files:
- core/box/free_policy_fast_v2_box.h (new)
- core/box/free_path_stats_box.h/c (policy_fast_v2_skip counter)
- core/front/malloc_tiny_fast.h (fast-path integration)
- docs/analysis/MID_V35_HOTPATH_OPT_1_DESIGN.md (new)
- docs/analysis/PHASE_3_GRADUATE_*.md (new)
- CURRENT_TASK.md (phase status update)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-12 18:40:08 +09:00
0c8583f91e
Phase TLS-UNIFY-3+: Refactoring - Unified ENV gates for C6 ULTRA
...
Consolidate C6 ULTRA ENV gate functions:
- tiny_c6_ultra_intrusive_env_box.h now contains both:
- tiny_c6_ultra_free_enabled() - C6 ULTRA routing (policy gate)
- tiny_c6_ultra_intrusive_enabled() - intrusive LIFO mode (TLS optimization)
- Simplified ENV gate management with clear separation of concerns
Removes code duplication by centralizing environment checks in single header.
Performance verified: ENV_OFF=56.4 Mop/s, ENV_ON=57.6 Mop/s (parity maintained)
Note: Avoided macro-based segment learning consolidation (C4/C5/C6) as it
would hinder compiler optimizations. Current inline approach is optimal.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 16:31:14 +09:00
1a8652a91a
Phase TLS-UNIFY-3: C6 intrusive freelist implementation (完成)
...
Implement C6 ULTRA intrusive LIFO freelist with ENV gating:
- Single-linked LIFO using next pointer at USER+1 offset
- tiny_next_store/tiny_next_load for pointer access (single source of truth)
- Segment learning via ss_fast_lookup (per-class seg_base/seg_end)
- ENV gate: HAKMEM_TINY_C6_ULTRA_INTRUSIVE_FL (default OFF)
- Counters: c6_ifl_push/pop/fallback in FREE_PATH_STATS
Files:
- core/box/tiny_ultra_tls_box.h: Added c6_head field for intrusive LIFO
- core/box/tiny_ultra_tls_box.c: Pop/push with intrusive branching (case 6)
- core/box/tiny_c6_ultra_intrusive_env_box.h: ENV gate (new)
- core/box/tiny_c6_intrusive_freelist_box.h: L1 pure LIFO (new)
- core/tiny_debug_ring.h: C6_IFL events
- core/box/free_path_stats_box.h/c: c6_ifl_* counters
A/B Test Results (1M iterations, ws=200, 257-512B):
- ENV_OFF (array): 56.6 Mop/s avg
- ENV_ON (intrusive): 57.6 Mop/s avg (+1.8%, within noise)
- Counters verified: c6_ifl_push=265890, c6_ifl_pop=265815, fallback=0
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 16:26:42 +09:00
d5ffb3eeb2
Fix MID v3.5 activation bugs: policy loop + malloc recursion
...
Two critical bugs fixed:
1. Policy snapshot infinite loop (smallobject_policy_v7.c):
- Condition `g_policy_v7_version == 0` caused reinit on every call
- Fixed via CAS to set global version to 1 after first init
2. Malloc recursion (smallobject_segment_mid_v3.c):
- Internal malloc() routed back through hakmem → MID v3.5 → segment
creation → malloc → infinite recursion / stack overflow
- Fixed by using mmap() directly for internal allocations:
- Segment struct, pages array, page metadata block
Performance results (bench_random_mixed 257-512B):
- Baseline (LEGACY): 34.0M ops/s
- MID_V35 ON (C6): 35.8M ops/s
- Improvement: +5.1% ✓
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-12 07:12:24 +09:00
212739607a
Phase v11a-3: MID v3.5 Activation (Build Complete)
...
Integrated MID v3.5 into active code path, making it available for C5/C6/C7 routing.
Key Changes:
- Policy Box: Added SMALL_ROUTE_MID_V35 with ENV gates (HAKMEM_MID_V35_ENABLED, HAKMEM_MID_V35_CLASSES)
- HotBox: Implemented small_mid_v35_alloc/free with TLS-cached page allocation
- Front Gate: Wired MID_V35 routing into malloc_tiny_fast.h (priority: ULTRA > MID_V35 > V7)
- Build: Added core/smallobject_mid_v35.o to all object lists
Architecture:
- Slot sizes: C5=384B, C6=512B, C7=1024B
- Page size: 64KB (170/128/64 slots)
- Integration: ColdIface v2 (refill/retire), Stats v2 (observation), Learner v2 (dormant)
Status: Build successful, ready for A/B benchmarking
Next: Performance validation (C6-heavy, C5+C6-only, Mixed benchmarks)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-12 06:52:14 +09:00
0dba67ba9d
Phase v11a-2: Core MID v3.5 implementation - segment, cold iface, stats, learner
...
Implement 5-layer infrastructure for multi-class MID v3.5 (C5-C7, 257-1KiB):
1. SegmentBox_mid_v3 (L2 Physical)
- core/smallobject_segment_mid_v3.c (9.5 KB)
- 2MiB segments, 64KiB pages (32 per segment)
- Per-class free page stacks (LIFO)
- RegionIdBox registration
- Slots: C5→170, C6→102, C7→64
2. ColdIface_mid_v3 (L2→L1)
- core/box/smallobject_cold_iface_mid_v3_box.h (NEW)
- core/smallobject_cold_iface_mid_v3.c (3.5 KB)
- refill: get page from free stack or new segment
- retire: calculate free_hit_ratio, publish stats, return to stack
- Clean separation: TLS cache for hot path, ColdIface for cold path
3. StatsBox_mid_v3 (L2→L3)
- core/smallobject_stats_mid_v3.c (7.2 KB)
- Circular buffer history (1000 events)
- Per-page metrics: class_idx, allocs, frees, free_hit_ratio_bps
- Periodic aggregation (every 100 retires)
- Learner notification callback
4. Learner v2 (L3)
- core/smallobject_learner_v2.c (11 KB)
- Multi-class aggregation: allocs[8], retire_count[8], avg_free_hit_bps[8]
- Exponential smoothing (90% history + 10% new)
- Per-class efficiency tracking
- Stats snapshot API
- Route decision disabled for v11a-2 (v11b feature)
5. Build Integration
- Modified Makefile: added 4 new .o files (segment, cold_iface, stats, learner)
- Updated box header prototypes
- Clean compilation, all dependencies resolved
Architecture Decision Implementation:
- v7 remains frozen (C5/C6 research preset)
- MID v3.5 becomes unified 257-1KiB main path
- Multi-class isolation: per-class free stacks
- Dormant infrastructure: linked but not active (zero overhead)
Performance:
- Build: clean compilation
- Sanity benchmark: 27.3M ops/s (no regression vs v10)
- Memory: ~30MB RSS (baseline maintained)
Design Compliance:
✅ Layer separation: L2 (segment) → L2 (cold iface) → L3 (stats) → L3 (learner)
✅ Hot path clean: alloc/free never touch stats/learner
✅ Backward compatible: existing MID v3 routes unchanged
✅ Transparent: v11a-2 is dormant (no behavior change)
Next Phase (v11a-3):
- Activate C5/C6/C7 routing through MID v3.5
- Connect TLS cache to segment refill
- Verify performance under load
- Then Phase v11a-4: dynamic C5 ratio routing
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com >
2025-12-12 06:37:06 +09:00