Phase 86: Free Path Legacy Mask (NO-GO, +0.25%)
## Summary Implemented Phase 86 "mask-only commit" optimization for free path: - Bitset mask (0x7f for C0-C6) to identify LEGACY classes - Direct call to tiny_legacy_fallback_free_base_with_env() - No indirect function pointers (avoids Phase 85's -0.86% regression) - Fail-fast on LARSON_FIX=1 (cross-thread validation incompatibility) ## Results (10-run SSOT) **NO-GO**: +0.25% improvement (threshold: +1.0%) - Control: 51,750,467 ops/s (CV: 2.26%) - Treatment: 51,881,055 ops/s (CV: 2.32%) - Delta: +0.25% (mean), -0.15% (median) ## Root Cause Competing optimizations plateau: 1. Phase 9/10 MONO LEGACY (+1.89%) already capture most free path benefit 2. Remaining margin insufficient to overcome: - Two branch checks (mask_enabled + has_class) - I-cache layout tax in hot path - Direct function call overhead ## Phase 85 vs Phase 86 | Metric | Phase 85 | Phase 86 | |--------|----------|----------| | Approach | Indirect calls + table | Bitset mask + direct call | | Result | -0.86% | +0.25% | | Verdict | NO-GO (regression) | NO-GO (insufficient) | Phase 86 correctly avoided indirect call penalties but revealed architectural limit: can't escape Phase 9/10 overlay without restructuring. ## Recommendation Free path optimization layer has reached practical ceiling: - Phase 9/10 +1.89% + Phase 6/19/FASTLANE +16-27% ≈ 18-29% total - Further attempts on ceremony elimination face same constraints - Recommend focus on different optimization layers (malloc, etc.) ## Files Changed ### New - core/box/free_path_legacy_mask_box.h (API + globals) - core/box/free_path_legacy_mask_box.c (refresh logic) ### Modified - core/bench_profile.h (added refresh call) - core/front/malloc_tiny_fast.h (added Phase 86 fast path check) - Makefile (added object files) - CURRENT_TASK.md (documented result) All changes conditional on HAKMEM_FREE_PATH_LEGACY_MASK=1 (default OFF). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -74,6 +74,8 @@
|
||||
#include "../box/free_cold_shape_stats_box.h" // Phase 5 E5-3a: Free cold shape stats
|
||||
#include "../box/free_tiny_fast_mono_dualhot_env_box.h" // Phase 9: MONO DUALHOT ENV gate
|
||||
#include "../box/free_tiny_fast_mono_legacy_direct_env_box.h" // Phase 10: MONO LEGACY DIRECT ENV gate
|
||||
#include "../box/free_path_commit_once_fixed_box.h" // Phase 85: Free path commit-once (LEGACY-only)
|
||||
#include "../box/free_path_legacy_mask_box.h" // Phase 86: Free path legacy mask (mask-only, no indirect calls)
|
||||
#include "../box/alloc_passdown_ssot_env_box.h" // Phase 60: Alloc pass-down SSOT
|
||||
|
||||
// Helper: current thread id (low 32 bits) for owner check
|
||||
@ -955,6 +957,39 @@ static inline int free_tiny_fast(void* ptr) {
|
||||
// Phase 19-3b: Consolidate ENV snapshot reads (capture once per free_tiny_fast call).
|
||||
const HakmemEnvSnapshot* env = hakmem_env_snapshot_enabled() ? hakmem_env_snapshot() : NULL;
|
||||
|
||||
// Phase 86: Free path legacy mask - Direct early exit for LEGACY classes (no indirect calls)
|
||||
// Conditions:
|
||||
// - ENV: HAKMEM_FREE_PATH_LEGACY_MASK=1
|
||||
// - class_idx in legacy_mask (LEGACY route, not ULTRA/MID/V7)
|
||||
// - LARSON_FIX=0 (checked at startup, fail-fast if enabled)
|
||||
if (__builtin_expect(free_path_legacy_mask_enabled_fast(), 0)) {
|
||||
if (__builtin_expect(free_path_legacy_mask_has_class((unsigned)class_idx), 0)) {
|
||||
// Direct path: Call legacy handler without policy snapshot, route, or mono checks
|
||||
tiny_legacy_fallback_free_base_with_env(base, (uint32_t)class_idx, env);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 85: Free path commit-once (LEGACY-only) - Skip policy/route/mono ceremony for committed C4-C7
|
||||
// Conditions:
|
||||
// - ENV: HAKMEM_FREE_PATH_COMMIT_ONCE=1
|
||||
// - class_idx in C4-C7 (129-256B LEGACY classes)
|
||||
// - Pre-computed at startup that class can use commit-once
|
||||
// - LARSON_FIX=0 (checked at startup, fail-fast if enabled)
|
||||
if (__builtin_expect(free_path_commit_once_enabled_fast(), 0)) {
|
||||
if (__builtin_expect((unsigned)class_idx >= 4u && (unsigned)class_idx <= 7u, 0)) {
|
||||
const unsigned cache_idx = (unsigned)class_idx - 4u;
|
||||
const struct FreePatchCommitOnceEntry* entry = &g_free_path_commit_once_entries[cache_idx];
|
||||
|
||||
if (__builtin_expect(entry->can_commit, 0)) {
|
||||
// Direct path: Call handler without policy snapshot, route, or mono checks
|
||||
FREE_PATH_STAT_INC(commit_once_hit);
|
||||
entry->handler(base, (uint32_t)class_idx, env);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 9: MONO DUALHOT early-exit for C0-C3 (skip policy snapshot, direct to legacy)
|
||||
// Conditions:
|
||||
// - ENV: HAKMEM_FREE_TINY_FAST_MONO_DUALHOT=1
|
||||
|
||||
Reference in New Issue
Block a user