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>
54 lines
1.5 KiB
C
54 lines
1.5 KiB
C
#ifndef HAKMEM_ALLOC_GATE_STATS_BOX_H
|
|
#define HAKMEM_ALLOC_GATE_STATS_BOX_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include "../hakmem_build_flags.h"
|
|
|
|
typedef struct AllocGateStats {
|
|
uint64_t total_calls; // malloc_tiny_fast 入口
|
|
|
|
uint64_t size_to_class_calls; // size→class 変換
|
|
uint64_t route_for_class_calls; // class→route 判定
|
|
uint64_t env_checks; // alloc-side ENV 判定数
|
|
|
|
// クラス別分布
|
|
uint64_t class_calls[8]; // C0〜C7 呼び出し数
|
|
} AllocGateStats;
|
|
|
|
// ENV gate
|
|
static inline bool alloc_gate_stats_enabled(void) {
|
|
#if !HAKMEM_DEBUG_COUNTERS
|
|
return false;
|
|
#else
|
|
static int g_enabled = -1;
|
|
if (__builtin_expect(g_enabled == -1, 0)) {
|
|
const char* e = getenv("HAKMEM_ALLOC_GATE_STATS");
|
|
g_enabled = (e && *e && *e != '0') ? 1 : 0;
|
|
}
|
|
return g_enabled;
|
|
#endif
|
|
}
|
|
|
|
// Global stats instance
|
|
extern AllocGateStats g_alloc_gate_stats;
|
|
|
|
// Increment macros (with unlikely guard)
|
|
#if HAKMEM_DEBUG_COUNTERS
|
|
#define ALLOC_GATE_STAT_INC(field) \
|
|
do { if (__builtin_expect(alloc_gate_stats_enabled(), 0)) { \
|
|
g_alloc_gate_stats.field++; \
|
|
} } while(0)
|
|
|
|
#define ALLOC_GATE_STAT_INC_CLASS(class_idx) \
|
|
do { if (__builtin_expect(alloc_gate_stats_enabled(), 0)) { \
|
|
if ((class_idx) >= 0 && (class_idx) < 8) g_alloc_gate_stats.class_calls[class_idx]++; \
|
|
} } while(0)
|
|
#else
|
|
#define ALLOC_GATE_STAT_INC(field) ((void)0)
|
|
#define ALLOC_GATE_STAT_INC_CLASS(class_idx) ((void)0)
|
|
#endif
|
|
|
|
#endif // HAKMEM_ALLOC_GATE_STATS_BOX_H
|