ENV Cleanup Step 9: Gate HAKMEM_SUPER_REG_DEBUG in super_registry.c

Gate HAKMEM_SUPER_REG_DEBUG environment variable behind
#if !HAKMEM_BUILD_RELEASE in register/unregister functions.

Changes:
- Wrap dbg variable initialization in hak_super_register()
- Wrap dbg_once static variable and ENV check in hak_super_unregister()
- Release builds use constant dbg = 0 for complete code elimination

Performance: 30.6M ops/s Larson (+1.0% improvement)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-28 01:46:50 +09:00
parent f8b0f38f78
commit 4540b01da0

View File

@ -51,9 +51,13 @@ int hak_super_register(uintptr_t base, SuperSlab* ss) {
int lg = ss->lg_size; // Phase 8.3: Get lg_size from SuperSlab int lg = ss->lg_size; // Phase 8.3: Get lg_size from SuperSlab
#if !HAKMEM_BUILD_RELEASE
// Debug logging (check ENV every time for now - performance not critical during debug) // Debug logging (check ENV every time for now - performance not critical during debug)
const char* dbg_env = getenv("HAKMEM_SUPER_REG_DEBUG"); const char* dbg_env = getenv("HAKMEM_SUPER_REG_DEBUG");
int dbg = (dbg_env && *dbg_env && *dbg_env != '0') ? 1 : 0; int dbg = (dbg_env && *dbg_env && *dbg_env != '0') ? 1 : 0;
#else
const int dbg = 0;
#endif
int h = hak_super_hash(base, lg); int h = hak_super_hash(base, lg);
@ -109,7 +113,11 @@ int hak_super_register(uintptr_t base, SuperSlab* ss) {
// Phase 8.3: ACE - Try both lg_sizes (we don't know which one was used) // Phase 8.3: ACE - Try both lg_sizes (we don't know which one was used)
// Phase 6: Registry Optimization - Also remove from per-class registry // Phase 6: Registry Optimization - Also remove from per-class registry
void hak_super_unregister(uintptr_t base) { void hak_super_unregister(uintptr_t base) {
#if !HAKMEM_BUILD_RELEASE
static int dbg_once = -1; // shared with register path for debug toggle static int dbg_once = -1; // shared with register path for debug toggle
#else
static const int dbg_once = 0;
#endif
if (!g_super_reg_initialized) return; if (!g_super_reg_initialized) return;
pthread_mutex_lock(&g_super_reg_lock); pthread_mutex_lock(&g_super_reg_lock);
@ -136,12 +144,14 @@ void hak_super_unregister(uintptr_t base) {
// Step 3: Clear lg_size (optional cleanup) // Step 3: Clear lg_size (optional cleanup)
e->lg_size = 0; e->lg_size = 0;
#if !HAKMEM_BUILD_RELEASE
if (__builtin_expect(dbg_once == -1, 0)) { if (__builtin_expect(dbg_once == -1, 0)) {
const char* e = getenv("HAKMEM_SUPER_REG_DEBUG"); dbg_once = (e && *e && *e!='0'); const char* e = getenv("HAKMEM_SUPER_REG_DEBUG"); dbg_once = (e && *e && *e!='0');
} }
if (dbg_once == 1) { if (dbg_once == 1) {
fprintf(stderr, "[SUPER_REG] unregister base=%p\n", (void*)base); fprintf(stderr, "[SUPER_REG] unregister base=%p\n", (void*)base);
} }
#endif
// Found in hash table, continue to per-class removal // Found in hash table, continue to per-class removal
goto hash_removed; goto hash_removed;