Priority-2 ENV Cache: hakmem_debug.c (1変数追加、1箇所置換)
【追加ENV変数】
- HAKMEM_TIMING (default: 0)
【置換ファイル】
- core/hakmem_debug.c (1箇所 → ENV Cache)
【変更詳細】
1. ENV Cache (hakmem_env_cache.h):
- 構造体に1変数追加 (47→48変数)
- hakmem_env_cache_init()に初期化追加
- アクセサマクロ追加
- カウント更新: 47→48
2. hakmem_debug.c:
- hkm_timing_init():
getenv("HAKMEM_TIMING") + strcmp() → HAK_ENV_TIMING_ENABLED()
- #include "hakmem_env_cache.h" 追加
【効果】
- デバッグタイミング初期化からgetenv()呼び出しを排除
- Cold pathだが、起動時のENV参照を削減
【テスト】
✅ make shared → 成功
✅ /tmp/test_mixed3_final → PASSED
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -4,6 +4,7 @@
|
|||||||
// Date: 2025-10-21
|
// Date: 2025-10-21
|
||||||
|
|
||||||
#include "hakmem_debug.h"
|
#include "hakmem_debug.h"
|
||||||
|
#include "hakmem_env_cache.h" // Priority-2: ENV cache
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -150,11 +151,8 @@ void hkm_timing_init(void) {
|
|||||||
if (g_initialized) return;
|
if (g_initialized) return;
|
||||||
|
|
||||||
#if !HAKMEM_BUILD_RELEASE
|
#if !HAKMEM_BUILD_RELEASE
|
||||||
// Check HAKMEM_TIMING environment variable (gated behind !HAKMEM_BUILD_RELEASE)
|
// Priority-2: Use cached ENV (gated behind !HAKMEM_BUILD_RELEASE)
|
||||||
const char* env = getenv("HAKMEM_TIMING");
|
g_timing_enabled = HAK_ENV_TIMING_ENABLED();
|
||||||
if (env && strcmp(env, "1") == 0) {
|
|
||||||
g_timing_enabled = 1;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
g_timing_enabled = 0; // Always disabled in release builds
|
g_timing_enabled = 0; // Always disabled in release builds
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -84,6 +84,9 @@ typedef struct {
|
|||||||
// ===== Warm Path: SmallMid (1 variable) =====
|
// ===== Warm Path: SmallMid (1 variable) =====
|
||||||
int smallmid_enable; // HAKMEM_SMALLMID_ENABLE (default: 0)
|
int smallmid_enable; // HAKMEM_SMALLMID_ENABLE (default: 0)
|
||||||
|
|
||||||
|
// ===== Cold Path: Debug/Timing (1 variable) =====
|
||||||
|
int timing_enabled; // HAKMEM_TIMING (default: 0)
|
||||||
|
|
||||||
} HakEnvCache;
|
} HakEnvCache;
|
||||||
|
|
||||||
// Global cache instance (initialized once at startup)
|
// Global cache instance (initialized once at startup)
|
||||||
@ -268,10 +271,17 @@ static inline void hakmem_env_cache_init(void) {
|
|||||||
g_hak_env_cache.smallmid_enable = (e && atoi(e) == 1) ? 1 : 0; // default: 0 (OFF)
|
g_hak_env_cache.smallmid_enable = (e && atoi(e) == 1) ? 1 : 0; // default: 0 (OFF)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== Cold Path: Debug/Timing =====
|
||||||
|
{
|
||||||
|
const char* e;
|
||||||
|
e = getenv("HAKMEM_TIMING");
|
||||||
|
g_hak_env_cache.timing_enabled = (e && strcmp(e, "1") == 0) ? 1 : 0; // default: 0 (OFF)
|
||||||
|
}
|
||||||
|
|
||||||
#if !HAKMEM_BUILD_RELEASE
|
#if !HAKMEM_BUILD_RELEASE
|
||||||
// Debug: Print cache summary (stderr only)
|
// Debug: Print cache summary (stderr only)
|
||||||
if (!g_hak_env_cache.quiet) {
|
if (!g_hak_env_cache.quiet) {
|
||||||
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 47);
|
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 48);
|
||||||
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
|
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
@ -334,4 +344,7 @@ static inline void hakmem_env_cache_init(void) {
|
|||||||
// Warm path: SmallMid
|
// Warm path: SmallMid
|
||||||
#define HAK_ENV_SMALLMID_ENABLE() (g_hak_env_cache.smallmid_enable)
|
#define HAK_ENV_SMALLMID_ENABLE() (g_hak_env_cache.smallmid_enable)
|
||||||
|
|
||||||
|
// Cold path: Debug/Timing
|
||||||
|
#define HAK_ENV_TIMING_ENABLED() (g_hak_env_cache.timing_enabled)
|
||||||
|
|
||||||
#endif // HAKMEM_ENV_CACHE_H
|
#endif // HAKMEM_ENV_CACHE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user