## Phase 2 Optimization Research Complete ### B1 (Header tax reduction v2) - NO-GO - HAKMEM_TINY_HEADER_MODE=LIGHT: -2.54% regression on Mixed - Decision: FREEZE as research box (ENV opt-in only) ### B3 (Routing branch shape optimization) - ADOPT - Mixed: +2.89% (48.41M → 49.80M ops/s) - C6-heavy: +9.13% (8.97M → 9.79M ops/s) - Strategy: LIKELY on LEGACY (hot), noinline,cold helper for rare routes - Implementation: Already in malloc_tiny_fast.h:252-267 - Profile updates: HAKMEM_TINY_ALLOC_ROUTE_SHAPE=1 now default ### B4 (Wrapper Layer Hot/Cold Split) - Preparation - Design memo: docs/analysis/PHASE2_B4_WRAPPER_SHAPE_1_DESIGN.md - Goal: Split malloc/free into hot/cold paths, reduce I-cache pressure - ENV gate: HAKMEM_WRAP_SHAPE=0/1 (added to wrapper_env_box) - Expected gain: +2-5% Mixed, +1-3% C6-heavy ## Analysis Summary - Background is visible: FREE DUALHOT + B3 routing optimizations work - Code layering is clean: winning boxes promoted to presets, losing boxes frozen with ENV guards - Remaining gap to mimalloc is wrapper layer + safety checks + policy snapshot - Further +5-10% still realistically achievable 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
28 lines
1003 B
C
28 lines
1003 B
C
// wrapper_env_box.h - Environment variable cache for malloc/free wrappers
|
|
// Eliminates getenv() calls from malloc/free hot paths
|
|
#pragma once
|
|
|
|
#include <stdatomic.h>
|
|
|
|
typedef struct {
|
|
int inited;
|
|
int step_trace; // HAKMEM_STEP_TRACE (default: 0)
|
|
int ld_safe_mode; // HAKMEM_LD_SAFE (default: 1)
|
|
int free_wrap_trace; // HAKMEM_FREE_WRAP_TRACE (default: 0)
|
|
int wrap_diag; // HAKMEM_WRAP_DIAG (default: 0) - log first few libc fallbacks
|
|
int wrap_shape; // HAKMEM_WRAP_SHAPE (default: 0) - Phase 2 B4: malloc/free hot/cold split
|
|
} wrapper_env_cfg_t;
|
|
|
|
extern wrapper_env_cfg_t g_wrapper_env;
|
|
|
|
void wrapper_env_init_once(void);
|
|
|
|
static inline const wrapper_env_cfg_t* wrapper_env_cfg(void) {
|
|
// Constructor ensures init at library load time
|
|
// This check prevents repeated initialization in multi-threaded context
|
|
if (__builtin_expect(!g_wrapper_env.inited, 0)) {
|
|
wrapper_env_init_once();
|
|
}
|
|
return &g_wrapper_env;
|
|
}
|