Remove debug overhead from release builds (19 hotspots)
Problem: - Release builds (-DHAKMEM_BUILD_RELEASE=1) still execute debug code - fprintf, getenv(), atomic counters in hot paths - Performance: 9M ops/s vs System malloc 43M ops/s (4.8x slower) Fixed hotspots: 1. hak_alloc_api.inc.h - atomic_fetch_add + fprintf every alloc 2. hak_free_api.inc.h - Free wrapper trace + route trace 3. hak_wrappers.inc.h - Malloc wrapper logs 4. tiny_free_fast.inc.h - getenv() every free (CRITICAL!) 5. hakmem_tiny_refill.inc.h - Expensive validation 6. hakmem_tiny_sfc.c - SFC initialization logs 7. tiny_alloc_fast_sfc.inc.h - getenv() caching Changes: - Guard all fprintf/printf with #if !HAKMEM_BUILD_RELEASE - Cache getenv() results in TLS variables (debug builds only) - Remove atomic counters from hot paths in release builds - Add no-op stubs for release builds Impact: - All debug code completely eliminated in release builds - Expected improvement: Limited (deeper profiling needed) - Root cause: Performance bottleneck exists beyond debug overhead Note: Benchmark results show debug removal alone insufficient for performance goals. Further investigation required with perf profiling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -102,7 +102,8 @@ static inline int ultra_sll_cap_for_class(int class_idx);
|
||||
static void eventq_push(int class_idx, uint32_t size);
|
||||
|
||||
// Debug-only: Validate that a base node belongs to the expected Tiny SuperSlab and is stride-aligned
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
// IMPORTANT: This is expensive validation, ONLY enabled in DEBUG builds
|
||||
#if !HAKMEM_BUILD_RELEASE && 0 // Disabled by default even in debug (enable with #if 1 if needed)
|
||||
static inline void tiny_debug_validate_node_base(int class_idx, void* node, const char* where) {
|
||||
if ((uintptr_t)node < 4096) {
|
||||
fprintf(stderr, "[SLL_NODE_SMALL] %s: node=%p cls=%d\n", where, node, class_idx);
|
||||
|
||||
Reference in New Issue
Block a user