Phase 35-39: FAST build optimization complete (+7.13% cumulative)
Phase 35-A: BENCH_MINIMAL gate function elimination (GO +4.39%) - tiny_front_v3_enabled() → constant true - tiny_metadata_cache_enabled() → constant 0 - learner_v7_enabled() → constant false - small_learner_v2_enabled() → constant false Phase 36: Policy snapshot init-once (GO +0.71%) - small_policy_v7_snapshot() version check skip in BENCH_MINIMAL - TLS cache for policy snapshot Phase 37: Standard TLS cache (NO-GO -0.07%) - TLS cache for Standard build attempted - Runtime gate overhead negates benefit Phase 38: FAST/OBSERVE/Standard workflow established - make perf_fast, make perf_observe targets - Scorecard and documentation updates Phase 39: Hot path gate constantization (GO +1.98%) - front_gate_unified_enabled() → constant 1 - alloc_dualhot_enabled() → constant 0 - g_bench_fast_front, g_v3_enabled blocks → compile-out - free_dispatch_stats_enabled() → constant false Results: - FAST v3: 56.04M ops/s (47.4% of mimalloc) - Standard: 53.50M ops/s (45.3% of mimalloc) - M1 target (50%): 5.5% remaining 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -3,8 +3,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "hakmem_build_flags.h" // Phase 36: HAKMEM_BENCH_MINIMAL
|
||||
#include "box/smallobject_policy_v7_box.h"
|
||||
#include "box/smallobject_learner_v7_box.h" // For Learner API
|
||||
#include "box/small_policy_snapshot_tls_box.h" // Phase 37: TLS cache
|
||||
|
||||
#ifndef likely
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
@ -18,6 +20,12 @@
|
||||
static SmallLearnerStatsV7 g_small_learner_stats_v7;
|
||||
static int g_learner_v7_enabled = -1; // -1: uninit, 0: disabled, 1: enabled
|
||||
|
||||
// Phase 36: BENCH_MINIMAL mode - learner is disabled (bench profiles don't use learner)
|
||||
#if HAKMEM_BENCH_MINIMAL
|
||||
static inline int learner_v7_enabled(void) {
|
||||
return 0; // Fixed OFF in bench mode
|
||||
}
|
||||
#else
|
||||
static inline int learner_v7_enabled(void) {
|
||||
if (unlikely(g_learner_v7_enabled < 0)) {
|
||||
// Phase v10: Learner default ON (when v7 is enabled)
|
||||
@ -33,6 +41,7 @@ static inline int learner_v7_enabled(void) {
|
||||
}
|
||||
return g_learner_v7_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// TLS Policy Snapshot (v7-7: version-based invalidation)
|
||||
@ -48,7 +57,46 @@ void small_policy_v7_bump_version(void) {
|
||||
}
|
||||
|
||||
const SmallPolicyV7* small_policy_v7_snapshot(void) {
|
||||
// Check if TLS cache is stale (version mismatch or uninitialized)
|
||||
#if HAKMEM_BENCH_MINIMAL
|
||||
// Phase 36: BENCH_MINIMAL mode - skip version check, use init-once TLS cache
|
||||
// Assumes: Learner disabled, policy doesn't change during benchmark
|
||||
static __thread int s_initialized = 0;
|
||||
if (unlikely(!s_initialized)) {
|
||||
small_policy_v7_init_from_env(&g_small_policy_v7);
|
||||
s_initialized = 1;
|
||||
}
|
||||
return &g_small_policy_v7;
|
||||
#else
|
||||
// Phase 37: TLS cache fast path (default ON)
|
||||
if (policy_snapshot_tls_enabled()) {
|
||||
SmallPolicySnapshotTLSCache* cache = small_policy_snapshot_tls_get();
|
||||
uint32_t gver = g_policy_v7_version;
|
||||
|
||||
// Fast path: cache valid → return immediately (no global read beyond version)
|
||||
if (small_policy_snapshot_tls_check(cache, gver)) {
|
||||
return cache->cached_ptr;
|
||||
}
|
||||
|
||||
// Slow path: refresh cache
|
||||
small_policy_v7_init_from_env(&g_small_policy_v7);
|
||||
|
||||
// v7-7: Apply Learner-driven route updates
|
||||
if (learner_v7_enabled() && g_small_learner_stats_v7.total_retires > 0) {
|
||||
small_policy_v7_update_from_learner(&g_small_learner_stats_v7, &g_small_policy_v7);
|
||||
}
|
||||
|
||||
// Initialize global version to 1 if uninitialized (0)
|
||||
if (gver == 0) {
|
||||
__sync_val_compare_and_swap(&g_policy_v7_version, 0, 1);
|
||||
gver = 1;
|
||||
}
|
||||
|
||||
// Update TLS cache
|
||||
small_policy_snapshot_tls_update(cache, &g_small_policy_v7, gver);
|
||||
return &g_small_policy_v7;
|
||||
}
|
||||
|
||||
// Fallback: original version-check path (HAKMEM_POLICY_SNAPSHOT_TLS=0)
|
||||
if (unlikely(g_small_policy_v7_version != g_policy_v7_version || g_policy_v7_version == 0)) {
|
||||
small_policy_v7_init_from_env(&g_small_policy_v7);
|
||||
|
||||
@ -65,6 +113,7 @@ const SmallPolicyV7* small_policy_v7_snapshot(void) {
|
||||
g_small_policy_v7_version = g_policy_v7_version;
|
||||
}
|
||||
return &g_small_policy_v7;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user