diff --git a/core/front/tiny_heap_v2.h b/core/front/tiny_heap_v2.h index 0a6fa563..a694dec4 100644 --- a/core/front/tiny_heap_v2.h +++ b/core/front/tiny_heap_v2.h @@ -46,28 +46,31 @@ extern __thread TinyHeapV2Mag g_tiny_heap_v2_mag[TINY_NUM_CLASSES]; extern __thread TinyHeapV2Stats g_tiny_heap_v2_stats[TINY_NUM_CLASSES]; // Enable flag (cached) +// ENV: HAKMEM_TINY_HEAP_V2 +// - 0: Disable TinyHeapV2 (use existing front only) +// - 1 (default): Enable TinyHeapV2 (Mode 0 Stealing, +18% @ 32B) static inline int tiny_heap_v2_enabled(void) { static int g_enable = -1; - static int g_first_call = 1; if (__builtin_expect(g_enable == -1, 0)) { const char* e = getenv("HAKMEM_TINY_HEAP_V2"); - g_enable = (e && *e && *e != '0') ? 1 : 0; + if (e && *e) { + g_enable = (*e != '0') ? 1 : 0; + } else { + g_enable = 1; // Default: ON (Phase 13-B decision) + } +#if !HAKMEM_BUILD_RELEASE fprintf(stderr, "[HeapV2-INIT] tiny_heap_v2_enabled() called: ENV='%s' → %d\n", e ? e : "(null)", g_enable); fflush(stderr); - } - if (g_first_call && g_enable) { - fprintf(stderr, "[HeapV2-FIRST] Returning enabled=%d\n", g_enable); - fflush(stderr); - g_first_call = 0; +#endif } return g_enable; } // Class-specific enable mask (cached) // ENV: HAKMEM_TINY_HEAP_V2_CLASS_MASK (bitmask: bit 0=C0, bit 1=C1, bit 2=C2, bit 3=C3) -// Default: 0xF (all classes C0-C3 enabled) -// Example: 0x2 = C1 only, 0x8 = C3 only, 0x6 = C1+C2 +// Default: 0xE (C1-C3 only, skip C0 8B due to -5% regression) +// Example: 0x2 = C1 only, 0x8 = C3 only, 0x6 = C1+C2, 0xF = all C0-C3 static inline int tiny_heap_v2_class_enabled(int class_idx) { static int g_class_mask = -1; if (__builtin_expect(g_class_mask == -1, 0)) { @@ -78,7 +81,7 @@ static inline int tiny_heap_v2_class_enabled(int class_idx) { long val = strtol(e, &endptr, 0); // 0 = auto-detect base (0x for hex, else decimal) g_class_mask = (int)val; } else { - g_class_mask = 0xF; // Default: C0-C3 all enabled + g_class_mask = 0xE; // Default: C1-C3 (16/32/64B), skip C0 8B (-5% regression) } }