diff --git a/core/box/hak_wrappers.inc.h b/core/box/hak_wrappers.inc.h index 41477c33..49c712d0 100644 --- a/core/box/hak_wrappers.inc.h +++ b/core/box/hak_wrappers.inc.h @@ -89,10 +89,14 @@ void* malloc(size_t size) { #ifndef NDEBUG uint64_t count = atomic_fetch_add(&malloc_count, 1); #endif +#if !HAKMEM_BUILD_RELEASE + // Debug-only trace counter: in release builds this atomic increment + // is disabled to avoid hot-path cache misses and contention. static _Atomic int g_wrap_malloc_trace_count = 0; if (atomic_fetch_add_explicit(&g_wrap_malloc_trace_count, 1, memory_order_relaxed) < 256) { HAK_TRACE("[wrap_malloc_enter]\n"); } +#endif // NDEBUG: malloc_count increment disabled - removes 27.55% bottleneck // Phase 20-2: BenchFast mode (structural ceiling measurement) @@ -226,11 +230,15 @@ void* malloc(size_t size) { } void free(void* ptr) { +#if !HAKMEM_BUILD_RELEASE + // Debug-only trace counters; disabled in release to keep free() hot path + // free of atomic increments. static _Atomic int g_wrap_free_trace_count = 0; if (atomic_fetch_add_explicit(&g_wrap_free_trace_count, 1, memory_order_relaxed) < 256) { HAK_TRACE("[wrap_free_enter]\n"); } atomic_fetch_add_explicit(&g_free_wrapper_calls, 1, memory_order_relaxed); +#endif if (!ptr) return; // Phase 20-2: BenchFast mode (structural ceiling measurement)