ENV cleanup: Add RELEASE guards to DEBUG ENV variables (14 vars)
Added compile-time guards (#if HAKMEM_BUILD_RELEASE) to eliminate DEBUG ENV variable overhead in RELEASE builds. Variables guarded (14 total): - HAKMEM_TINY_TRACE_RING, HAKMEM_TINY_DUMP_RING_ATEXIT - HAKMEM_TINY_RF_TRACE, HAKMEM_TINY_MAILBOX_TRACE - HAKMEM_TINY_MAILBOX_TRACE_LIMIT, HAKMEM_TINY_MAILBOX_SLOWDISC - HAKMEM_TINY_MAILBOX_SLOWDISC_PERIOD - HAKMEM_SS_PREWARM_DEBUG, HAKMEM_SS_FREE_DEBUG - HAKMEM_TINY_FRONT_METRICS, HAKMEM_TINY_FRONT_DUMP - HAKMEM_TINY_COUNTERS_DUMP, HAKMEM_TINY_REFILL_DUMP - HAKMEM_PTR_TRACE_DUMP, HAKMEM_PTR_TRACE_VERBOSE Files modified (9 core files): - core/tiny_debug_ring.c (ring trace/dump) - core/box/mailbox_box.c (mailbox trace + slowdisc) - core/tiny_refill.h (refill trace) - core/hakmem_tiny_superslab.c (superslab debug) - core/box/ss_allocation_box.c (allocation debug) - core/tiny_superslab_free.inc.h (free debug) - core/box/front_metrics_box.c (frontend metrics) - core/hakmem_tiny_stats.c (stats dump) - core/ptr_trace.h (pointer trace) Bug fixes during implementation: 1. mailbox_box.c - Fixed variable scope (moved 'used' outside guard) 2. hakmem_tiny_stats.c - Fixed incomplete declarations (on1, on2) Impact: - Binary size: -85KB total - bench_random_mixed_hakmem: 319K → 305K (-14K, -4.4%) - larson_hakmem: 380K → 309K (-71K, -18.7%) - Performance: No regression (16.9-17.9M ops/s maintained) - Functional: All tests pass (Random Mixed + Larson) - Behavior: DEBUG ENV vars correctly ignored in RELEASE builds Testing: - Build: Clean compilation (warnings only, pre-existing) - 100K Random Mixed: 16.9-17.9M ops/s (PASS) - 10K Larson: 25.9M ops/s (PASS) - DEBUG ENV verification: Correctly ignored (PASS) Result: 14 DEBUG ENV variables now have zero overhead in RELEASE builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -177,10 +177,14 @@ SuperSlab* superslab_allocate(uint8_t size_class) {
|
||||
|
||||
// Debug logging flag (lazy init)
|
||||
static __thread int dbg = -1;
|
||||
#if HAKMEM_BUILD_RELEASE
|
||||
dbg = 0;
|
||||
#else
|
||||
if (__builtin_expect(dbg == -1, 0)) {
|
||||
const char* e = getenv("HAKMEM_SS_PREWARM_DEBUG");
|
||||
dbg = (e && *e && *e != '0') ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Phase 9: Try LRU cache first (lazy deallocation)
|
||||
SuperSlab* cached_ss = hak_ss_lru_pop(size_class);
|
||||
@ -296,10 +300,14 @@ void superslab_free(SuperSlab* ss) {
|
||||
|
||||
// ADD DEBUG LOGGING
|
||||
static __thread int dbg = -1;
|
||||
#if HAKMEM_BUILD_RELEASE
|
||||
dbg = 0;
|
||||
#else
|
||||
if (__builtin_expect(dbg == -1, 0)) {
|
||||
const char* e = getenv("HAKMEM_SS_FREE_DEBUG");
|
||||
dbg = (e && *e && *e != '0') ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
if (dbg == 1) {
|
||||
fprintf(stderr, "[SS_FREE] CALLED: ss=%p lg_size=%d active_slabs=%u\n",
|
||||
(void*)ss, ss->lg_size, ss->active_slabs);
|
||||
|
||||
Reference in New Issue
Block a user