Files
hakmem/core/box/tiny_static_route_box.h
Moe Charm (CI) 1798ed656d Phase 3 C3: Tiny Static Routing Box Implementation (Step 1A)
Research Box Implementation:
- core/box/tiny_static_route_box.h: TinyStaticRoute struct & API
- core/box/tiny_static_route_box.c: Static route table management
- Makefile: Added tiny_static_route_box.o to 3 OBJS lists

Design:
- ENV gate: HAKMEM_TINY_STATIC_ROUTE=0/1 (default: 0)
- Learner auto-disable: If HAKMEM_TINY_LEARNER_ENABLED=1, force OFF
- Constructor priority: 102 (runs after wrapper_env_ctor at 101)
- Thread-safe: Atomic CAS for exactly-once initialization

Baseline Profiling (Step 0 Complete):
  - Throughput: 46.2M ops/s (10M iterations × 400 ws)
  - Instructions/cycle: 2.11 insn/cycle
  - Frontend stalls: 10.62% (memory latency bottleneck)
  - Cache-misses: 3.46% of references
  Expected C3 gain: +5-8% (policy_snapshot bypass)

Next Steps (Step 1B onwards):
  1. Integrate static route into malloc_tiny_fast_for_class()
  2. A/B test: Mixed 10-run, expect +1% minimum for GO
  3. Decision: GO if +1%, NO-GO if -1%, else freeze

Status:
   Phase 2 (B3+B4): +4.4% cumulative
   Phase 3 planning & C3 Step 0-1A complete
   Phase 3 C3 Step 1B-3 pending (malloc integration & testing)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-13 18:04:14 +09:00

29 lines
1010 B
C

// tiny_static_route_box.h - Static routing table for policy_snapshot bypass (Phase 3 C3)
// Eliminates per-malloc policy_snapshot + learner evaluation overhead
// ENV gate: HAKMEM_TINY_STATIC_ROUTE=0/1 (default 0)
#pragma once
#include "smallobject_policy_v7_box.h"
typedef struct {
int inited;
SmallRouteKind route_kind[8]; // C0-C7 static route (determined at init, no learner update)
} TinyStaticRoute;
extern TinyStaticRoute g_tiny_static_route;
// Initialize static route table (called once, at library load time)
// Returns 1 if static routing is enabled and initialized, 0 otherwise
int tiny_static_route_init_once(void);
// Get static route for class_idx, or 0 if not enabled
// (Returns route_kind, or 0 if disabled/uninitialized)
SmallRouteKind tiny_static_route_get_kind(int class_idx);
// Refresh from ENV (for bench_apply_profile() sync)
void tiny_static_route_refresh_from_env(void);
// Check if static routing is enabled (cached ENV value)
int tiny_static_route_enabled(void);