Phase MID-V35-HOTPATH-OPT-1 complete: +7.3% on C6-heavy

Step 0: Geometry SSOT
  - New: core/box/smallobject_mid_v35_geom_box.h (L1/L2 consistency)
  - Fix: C6 slots/page 102→128 in L2 (smallobject_cold_iface_mid_v3.c)
  - Applied: smallobject_mid_v35.c, smallobject_segment_mid_v3.c

Step 1-3: ENV gates for hotpath optimizations
  - New: core/box/mid_v35_hotpath_env_box.h
    * HAKMEM_MID_V35_HEADER_PREFILL (default 0)
    * HAKMEM_MID_V35_HOT_COUNTS (default 1)
    * HAKMEM_MID_V35_C6_FASTPATH (default 0)
  - Implementation: smallobject_mid_v35.c
    * Header prefill at refill boundary (Step 1)
    * Gated alloc_count++ in hot path (Step 2)
    * C6 specialized fast path with constant slot_size (Step 3)

A/B Results:
  C6-heavy (257–768B): 8.75M→9.39M ops/s (+7.3%, 5-run mean) 
  Mixed (16–1024B): 9.98M→9.96M ops/s (-0.2%, within noise) ✓

Decision: FROZEN - defaults OFF, C6-heavy推奨ON, Mixed現状維持
Documentation: ENV_PROFILE_PRESETS.md updated

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-12 19:19:25 +09:00
parent e95e61f0ff
commit fe70e3baf5
9 changed files with 211 additions and 57 deletions

View File

@ -0,0 +1,52 @@
// mid_v35_hotpath_env_box.h - Phase MID-V35-HOTPATH-OPT-1 ENV gates
//
// Step 1: HAKMEM_MID_V35_HEADER_PREFILL (default 0)
// - ON: prefill headers at refill boundary, skip in hot path
// Step 2: HAKMEM_MID_V35_HOT_COUNTS (default 1)
// - OFF: skip alloc_count++ in hot path (free_count/retire kept)
// Step 3: HAKMEM_MID_V35_C6_FASTPATH (default 0)
// - ON: use specialized C6 fast path with constant slot size
//
#ifndef HAKMEM_MID_V35_HOTPATH_ENV_BOX_H
#define HAKMEM_MID_V35_HOTPATH_ENV_BOX_H
#include <stdlib.h>
#include <stdbool.h>
// Step 1: Header prefill at refill boundary
// Default OFF (conservative)
static inline bool mid_v35_header_prefill_enabled(void) {
static int g_enabled = -1;
if (__builtin_expect(g_enabled >= 0, 1)) {
return g_enabled == 1;
}
const char* e = getenv("HAKMEM_MID_V35_HEADER_PREFILL");
g_enabled = (e && *e == '1') ? 1 : 0;
return g_enabled == 1;
}
// Step 2: Hot counts (alloc_count++ in hot path)
// Default ON (for compatibility/correctness)
static inline bool mid_v35_hot_counts_enabled(void) {
static int g_enabled = -1;
if (__builtin_expect(g_enabled >= 0, 1)) {
return g_enabled == 1;
}
const char* e = getenv("HAKMEM_MID_V35_HOT_COUNTS");
g_enabled = (e && *e == '0') ? 0 : 1; // default ON
return g_enabled == 1;
}
// Step 3: C6 specialized fast path
// Default OFF (conservative)
static inline bool mid_v35_c6_fastpath_enabled(void) {
static int g_enabled = -1;
if (__builtin_expect(g_enabled >= 0, 1)) {
return g_enabled == 1;
}
const char* e = getenv("HAKMEM_MID_V35_C6_FASTPATH");
g_enabled = (e && *e == '1') ? 1 : 0;
return g_enabled == 1;
}
#endif // HAKMEM_MID_V35_HOTPATH_ENV_BOX_H

View File

@ -0,0 +1,45 @@
// smallobject_mid_v35_geom_box.h - Phase MID-V35-HOTPATH-OPT-1 Step 0
//
// Single Source of Truth for MID v3.5 geometry (C5-C7)
// All layers (L1 HotBox, L2 ColdIface, Segment) must use these helpers.
//
// Geometry (64KB page):
// C5: 384B slots, 170 slots/page (257-384B)
// C6: 512B slots, 128 slots/page (385-512B)
// C7: 1024B slots, 64 slots/page (513-1024B)
//
#ifndef HAKMEM_SMALLOBJECT_MID_V35_GEOM_BOX_H
#define HAKMEM_SMALLOBJECT_MID_V35_GEOM_BOX_H
#include <stdint.h>
#include <stddef.h>
// Page size for MID v3.5 (64KB)
#define MID_V35_PAGE_SIZE (64 * 1024)
// Slot size by class_idx (C5-C7 only, others return 0)
static inline size_t mid_v35_slot_size(uint32_t class_idx) {
switch (class_idx) {
case 5: return 384; // C5: 257-384B
case 6: return 512; // C6: 385-512B
case 7: return 1024; // C7: 513-1024B
default: return 0;
}
}
// Slots per page by class_idx (C5-C7 only, others return 0)
static inline uint32_t mid_v35_slots_per_page(uint32_t class_idx) {
switch (class_idx) {
case 5: return 170; // 65536 / 384 = 170
case 6: return 128; // 65536 / 512 = 128
case 7: return 64; // 65536 / 1024 = 64
default: return 0;
}
}
// Validate class_idx is in MID v3.5 range (C5-C7)
static inline int mid_v35_class_valid(uint32_t class_idx) {
return (class_idx >= 5 && class_idx <= 7);
}
#endif // HAKMEM_SMALLOBJECT_MID_V35_GEOM_BOX_H