Priority-2 ENV Cache: hakmem_batch.c (1変数追加、1箇所置換)
【追加ENV変数】
- HAKMEM_BATCH_BG (default: 0)
【置換ファイル】
- core/hakmem_batch.c (1箇所 → ENV Cache)
【変更詳細】
1. ENV Cache (hakmem_env_cache.h):
- 構造体に1変数追加 (48→49変数)
- hakmem_env_cache_init()に初期化追加
- アクセサマクロ追加
- カウント更新: 48→49
2. hakmem_batch.c:
- batch_init():
getenv("HAKMEM_BATCH_BG") → HAK_ENV_BATCH_BG()
- #include "hakmem_env_cache.h" 追加
【効果】
- Batch初期化から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:
@ -10,6 +10,7 @@
|
||||
#include "hakmem_batch.h"
|
||||
#include "hakmem_sys.h" // Phase 6.11.1: Syscall wrappers with timing
|
||||
#include "hakmem_whale.h" // Phase 6.11.1: Whale fast-path cache
|
||||
#include "hakmem_env_cache.h" // Priority-2: ENV cache
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -70,8 +71,8 @@ void hak_batch_init(void) {
|
||||
g_immediate_dontneed = 0;
|
||||
|
||||
// Background worker toggle
|
||||
const char* e_bg = getenv("HAKMEM_BATCH_BG");
|
||||
if (e_bg) g_bg_enabled = (atoi(e_bg) != 0);
|
||||
// Priority-2: Use cached ENV
|
||||
g_bg_enabled = HAK_ENV_BATCH_BG();
|
||||
|
||||
// Sync primitives
|
||||
pthread_mutex_init(&g_batch_mu, NULL);
|
||||
|
||||
@ -87,6 +87,9 @@ typedef struct {
|
||||
// ===== Cold Path: Debug/Timing (1 variable) =====
|
||||
int timing_enabled; // HAKMEM_TIMING (default: 0)
|
||||
|
||||
// ===== Cold Path: Batch (1 variable) =====
|
||||
int batch_bg; // HAKMEM_BATCH_BG (default: 0)
|
||||
|
||||
} HakEnvCache;
|
||||
|
||||
// Global cache instance (initialized once at startup)
|
||||
@ -278,10 +281,17 @@ static inline void hakmem_env_cache_init(void) {
|
||||
g_hak_env_cache.timing_enabled = (e && strcmp(e, "1") == 0) ? 1 : 0; // default: 0 (OFF)
|
||||
}
|
||||
|
||||
// ===== Cold Path: Batch =====
|
||||
{
|
||||
const char* e;
|
||||
e = getenv("HAKMEM_BATCH_BG");
|
||||
g_hak_env_cache.batch_bg = (e && atoi(e) != 0) ? 1 : 0; // default: 0 (OFF)
|
||||
}
|
||||
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
// Debug: Print cache summary (stderr only)
|
||||
if (!g_hak_env_cache.quiet) {
|
||||
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 48);
|
||||
fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 49);
|
||||
fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
@ -347,4 +357,7 @@ static inline void hakmem_env_cache_init(void) {
|
||||
// Cold path: Debug/Timing
|
||||
#define HAK_ENV_TIMING_ENABLED() (g_hak_env_cache.timing_enabled)
|
||||
|
||||
// Cold path: Batch
|
||||
#define HAK_ENV_BATCH_BG() (g_hak_env_cache.batch_bg)
|
||||
|
||||
#endif // HAKMEM_ENV_CACHE_H
|
||||
|
||||
Reference in New Issue
Block a user