From ad852e5d5e218ba381fd6641d81ece75361c4bee Mon Sep 17 00:00:00 2001 From: "Moe Charm (CI)" Date: Tue, 2 Dec 2025 20:58:25 +0900 Subject: [PATCH] =?UTF-8?q?Priority-2=20ENV=20Cache:=20hakmem=5Fbatch.c=20?= =?UTF-8?q?(1=E5=A4=89=E6=95=B0=E8=BF=BD=E5=8A=A0=E3=80=811=E7=AE=87?= =?UTF-8?q?=E6=89=80=E7=BD=AE=E6=8F=9B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【追加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 --- core/hakmem_batch.c | 5 +++-- core/hakmem_env_cache.h | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/hakmem_batch.c b/core/hakmem_batch.c index f8fb0377..03d4cd76 100644 --- a/core/hakmem_batch.c +++ b/core/hakmem_batch.c @@ -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 #include #include @@ -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); diff --git a/core/hakmem_env_cache.h b/core/hakmem_env_cache.h index 6b14b0ff..103078a2 100644 --- a/core/hakmem_env_cache.h +++ b/core/hakmem_env_cache.h @@ -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