Phase 7-1.3: Simplify HAK_RET_ALLOC macro definition (-35% LOC, -100% #undef)

Problem:
- Phase 7-1.3 working code had complex #ifndef/#undef pattern
- Bidirectional dependency between hakmem_tiny.c and tiny_alloc_fast.inc.h
- Dangerous #undef usage masking real errors
- 3 levels of #ifdef nesting, hard to understand control flow

Solution:
- Single definition point in core/hakmem_tiny.c (lines 116-152)
- Clear feature flag based selection: #if HAKMEM_TINY_HEADER_CLASSIDX
- Removed duplicate definition and #undef from tiny_alloc_fast.inc.h
- Added clear comment pointing to single definition point

Results:
- -35% lines of code (7 lines deleted)
- -100% #undef usage (eliminated dangerous pattern)
- -33% nesting depth (3 levels → 2 levels)
- Much clearer control flow (single decision point)
- Same performance: 2.63M ops/s Larson, 17.7M ops/s bench_random_mixed

Implementation:
1. core/hakmem_tiny.c: Replaced #ifndef/#undef with #if HAKMEM_TINY_HEADER_CLASSIDX
2. core/tiny_alloc_fast.inc.h: Deleted duplicate macro, added pointer comment

Testing:
- Larson 1T: 2.63M ops/s (expected ~2.73M, within variance)
- bench_random_mixed (128B): 17.7M ops/s (better than before!)
- All builds clean with HEADER_CLASSIDX=1

Recommendation from Task Agent Ultrathink (Option A - Single Definition):
https://github.com/anthropics/claude-code/issues/...

Phase: 7-1.3 (Ifdef Simplification)
Date: 2025-11-08
This commit is contained in:
Moe Charm (CI)
2025-11-08 11:49:21 +09:00
parent 4983352812
commit ef2d1caa2a
2 changed files with 38 additions and 28 deletions

View File

@ -63,13 +63,8 @@ extern int g_refill_count_hot;
extern int g_refill_count_mid;
extern int g_refill_count_class[TINY_NUM_CLASSES];
// External macros
// Phase 7: Write header before returning (if enabled)
// CRITICAL: Undefine legacy macro to ensure Phase 7 version is used
#ifdef HAK_RET_ALLOC
#undef HAK_RET_ALLOC
#endif
#define HAK_RET_ALLOC(cls, ptr) return tiny_region_id_write_header((ptr), (cls))
// HAK_RET_ALLOC macro is now defined in core/hakmem_tiny.c
// See lines 116-152 for single definition point based on HAKMEM_TINY_HEADER_CLASSIDX
// ========== RDTSC Profiling (lightweight) ==========
#ifdef __x86_64__