TinyHeapV2: Enable by default with optimized settings
Changes: - Default: TinyHeapV2 ON (was OFF, now enabled without ENV) - Default CLASS_MASK: 0xE (C1-C3 only, skip C0 8B due to -5% regression) - Remove debug fprintf overhead in Release builds (HAKMEM_BUILD_RELEASE guard) Performance (100K iterations, workset=128, default settings): - 16B: 43.9M → 47.7M ops/s (+8.7%) - 32B: 41.9M → 44.8M ops/s (+6.9%) - 64B: 51.2M → 50.9M ops/s (-0.6%, within noise) Key fix: Debug fprintf in tiny_heap_v2_enabled() caused 20-30% overhead - Before: 36-42M ops/s (with debug log) - After: 44-48M ops/s (debug log disabled in Release) ENV override: - HAKMEM_TINY_HEAP_V2=0 to disable - HAKMEM_TINY_HEAP_V2_CLASS_MASK=0xF to enable all C0-C3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user