**目的**: free dispatcher(29%)の内訳を細分化して計測。 **実装内容**: - FreeDispatchStats 構造体追加(ENV: HAKMEM_FREE_DISPATCH_STATS, default 0) - カウンタ: total_calls / domain (tiny/mid/large) / route (ultra/legacy/pool/v6) / env_checks / route_for_class_calls - hak_free_at / tiny_route_for_class / tiny_route_snapshot_init にカウンタ埋め込み - 挙動変更なし(計測のみ、ENV OFF 時は overhead ゼロ) **計測結果**: Mixed 16-1024B (1M iter, ws=400): - total=8,081, route_calls=267,967, env_checks=9 - BENCH_FAST_FRONT により大半は早期リターン - route_for_class は主に alloc 側で呼ばれる(267k calls vs 8k frees) - ENV check は初期化時の 9回のみ(snapshot 効果) C6-heavy (257-768B, 1M iter, ws=400): - total=500,099, route_calls=1,034, env_checks=9 - fg_classify_domain に到達する free が多い - route_for_class 呼び出しは極小(snapshot 効果) **結論**: - ENV check は既に十分最適化されている(初期化時のみ) - route_for_class は alloc 側での呼び出しが主で、free 側は snapshot で O(1) - 次フェーズ(OPT-2)では別のアプローチを検討 **ドキュメント追加**: - docs/analysis/FREE_DISPATCHER_ANALYSIS.md(新規) - CURRENT_TASK.md に Phase FREE-DISPATCHER-OPT-1 セクション追加 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
47 lines
1.4 KiB
C
47 lines
1.4 KiB
C
#ifndef HAKMEM_FREE_DISPATCH_STATS_BOX_H
|
|
#define HAKMEM_FREE_DISPATCH_STATS_BOX_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct FreeDispatchStats {
|
|
uint64_t total_calls;
|
|
|
|
// Domain classification
|
|
uint64_t domain_tiny;
|
|
uint64_t domain_mid;
|
|
uint64_t domain_large;
|
|
|
|
// Route classification (tiny domain)
|
|
uint64_t route_ultra; // C4-C7 ULTRA 直行
|
|
uint64_t route_tiny_legacy; // Tiny legacy path
|
|
uint64_t route_pool_v1; // pool v1 経由
|
|
uint64_t route_core_v6; // core v6 (C6-only)
|
|
|
|
// Performance counters
|
|
uint64_t env_checks; // ENV 読み回数(概算)
|
|
uint64_t route_for_class_calls; // tiny_route_for_class() 呼び出し回数
|
|
} FreeDispatchStats;
|
|
|
|
// ENV gate
|
|
static inline bool free_dispatch_stats_enabled(void) {
|
|
static int g_enabled = -1;
|
|
if (__builtin_expect(g_enabled == -1, 0)) {
|
|
const char* e = getenv("HAKMEM_FREE_DISPATCH_STATS");
|
|
g_enabled = (e && *e && *e != '0') ? 1 : 0;
|
|
}
|
|
return g_enabled;
|
|
}
|
|
|
|
// Global stats instance
|
|
extern FreeDispatchStats g_free_dispatch_stats;
|
|
|
|
// Increment macros (with unlikely guard)
|
|
#define FREE_DISPATCH_STAT_INC(field) \
|
|
do { if (__builtin_expect(free_dispatch_stats_enabled(), 0)) { \
|
|
g_free_dispatch_stats.field++; \
|
|
} } while(0)
|
|
|
|
#endif // HAKMEM_FREE_DISPATCH_STATS_BOX_H
|