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:
Moe Charm (CI)
2025-11-13 13:32:58 +09:00
parent c28314fb96
commit 6570f52f7b
8 changed files with 661 additions and 3 deletions

View File

@ -121,6 +121,7 @@ void sfc_init(void) {
// Register shutdown hook for optional stats dump
atexit(sfc_shutdown);
#if !HAKMEM_BUILD_RELEASE
// One-shot debug log
static int debug_printed = 0;
if (!debug_printed) {
@ -137,6 +138,7 @@ void sfc_init(void) {
}
}
}
#endif
// Ensure stats (if requested) are printed at process exit.
// This is inexpensive and guarded inside sfc_shutdown by HAKMEM_SFC_STATS_DUMP.