Phase 14 v1: Pointer-Chase Reduction (tcache) NEUTRAL (+0.20%)
Implementation:
- Intrusive LIFO tcache layer (L1) before UnifiedCache
- TLS per-class bins (head pointer + count)
- Intrusive next pointers (via tiny_next_store/load SSOT)
- Cap: 64 blocks per class (default)
- ENV: HAKMEM_TINY_TCACHE=0/1 (default: 0, OFF)
A/B Test Results (Mixed 10-run):
- Baseline (TCACHE=0): 51,083,379 ops/s
- Optimized (TCACHE=1): 51,186,838 ops/s
- Mean delta: +0.20% (below +1.0% GO threshold)
- Median delta: +0.59%
Verdict: NEUTRAL - Freeze as research box (default OFF)
Root Cause (v1 wiring incomplete):
- Free side pushes to tcache via unified_cache_push()
- Alloc hot path (tiny_hot_alloc_fast) doesn't consume tcache
- tcache becomes "sink" without alloc-side pop → ROI not measurable
Files:
- Created: core/box/tiny_tcache_{env_box,box}.h, tiny_tcache_env_box.c
- Modified: core/front/tiny_unified_cache.h (integration)
- Modified: core/bench_profile.h (refresh sync)
- Modified: Makefile (build integration)
- Results: docs/analysis/PHASE14_POINTER_CHASE_REDUCTION_1_AB_TEST_RESULTS.md
- v2 Instructions: docs/analysis/PHASE14_POINTER_CHASE_REDUCTION_2_NEXT_INSTRUCTIONS.md
Next: Phase 14 v2 (connect tcache to tiny_front_hot_box alloc/free hot path)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
68
core/box/tiny_tcache_env_box.c
Normal file
68
core/box/tiny_tcache_env_box.c
Normal file
@ -0,0 +1,68 @@
|
||||
// ============================================================================
|
||||
// Phase 14 v1: Tiny tcache ENV Box (L0) - Implementation
|
||||
// ============================================================================
|
||||
|
||||
#include "tiny_tcache_env_box.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// ============================================================================
|
||||
// Global State
|
||||
// ============================================================================
|
||||
|
||||
_Atomic int g_tiny_tcache_enabled = -1;
|
||||
_Atomic uint16_t g_tiny_tcache_cap = 0;
|
||||
|
||||
// ============================================================================
|
||||
// Init (Cold Path)
|
||||
// ============================================================================
|
||||
|
||||
int tiny_tcache_env_init(void) {
|
||||
const char* env_enabled = getenv("HAKMEM_TINY_TCACHE");
|
||||
const char* env_cap = getenv("HAKMEM_TINY_TCACHE_CAP");
|
||||
|
||||
int enabled = 0; // default: OFF (opt-in)
|
||||
uint16_t cap = 64; // default: 64 (glibc tcache-like)
|
||||
|
||||
// Parse HAKMEM_TINY_TCACHE
|
||||
if (env_enabled && (env_enabled[0] == '1' || strcmp(env_enabled, "true") == 0 || strcmp(env_enabled, "TRUE") == 0)) {
|
||||
enabled = 1;
|
||||
}
|
||||
|
||||
// Parse HAKMEM_TINY_TCACHE_CAP
|
||||
if (env_cap && *env_cap) {
|
||||
int parsed = atoi(env_cap);
|
||||
if (parsed > 0 && parsed <= 65535) {
|
||||
cap = (uint16_t)parsed;
|
||||
}
|
||||
}
|
||||
|
||||
// Cache results
|
||||
atomic_store_explicit(&g_tiny_tcache_enabled, enabled, memory_order_relaxed);
|
||||
atomic_store_explicit(&g_tiny_tcache_cap, cap, memory_order_relaxed);
|
||||
|
||||
// Log once (stderr for immediate visibility)
|
||||
if (enabled) {
|
||||
char msg[128];
|
||||
int n = snprintf(msg, sizeof(msg), "[TINY_TCACHE] enabled (cap=%u)\n", (unsigned)cap);
|
||||
if (n > 0 && n < (int)sizeof(msg)) {
|
||||
ssize_t w = write(2, msg, (size_t)n);
|
||||
(void)w;
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Refresh (Cold Path, called from bench_profile)
|
||||
// ============================================================================
|
||||
|
||||
void tiny_tcache_env_refresh_from_env(void) {
|
||||
// Reset to uninitialized state (-1 / 0)
|
||||
// Next call to tiny_tcache_enabled() / tiny_tcache_cap() will re-read ENV
|
||||
atomic_store_explicit(&g_tiny_tcache_enabled, -1, memory_order_relaxed);
|
||||
atomic_store_explicit(&g_tiny_tcache_cap, 0, memory_order_relaxed);
|
||||
}
|
||||
Reference in New Issue
Block a user