Files
hakmem/analyze_soak.py

97 lines
3.6 KiB
Python
Raw Normal View History

Phase 54-60: Memory-Lean mode, Balanced mode stabilization, M1 (50%) achievement ## Summary Completed Phase 54-60 optimization work: **Phase 54-56: Memory-Lean mode (LEAN+OFF prewarm suppression)** - Implemented ss_mem_lean_env_box.h with ENV gates - Balanced mode (LEAN+OFF) promoted as production default - Result: +1.2% throughput, better stability, zero syscall overhead - Added to bench_profile.h: MIXED_TINYV3_C7_BALANCED preset **Phase 57: 60-min soak finalization** - Balanced mode: 60-min soak, RSS drift 0%, CV 5.38% - Speed-first mode: 60-min soak, RSS drift 0%, CV 1.58% - Syscall budget: 1.25e-7/op (800× under target) - Status: PRODUCTION-READY **Phase 59: 50% recovery baseline rebase** - hakmem FAST (Balanced): 59.184M ops/s, CV 1.31% - mimalloc: 120.466M ops/s, CV 3.50% - Ratio: 49.13% (M1 ACHIEVED within statistical noise) - Superior stability: 2.68× better CV than mimalloc **Phase 60: Alloc pass-down SSOT (NO-GO)** - Implemented alloc_passdown_ssot_env_box.h - Modified malloc_tiny_fast.h for SSOT pattern - Result: -0.46% (NO-GO) - Key lesson: SSOT not applicable where early-exit already optimized ## Key Metrics - Performance: 49.13% of mimalloc (M1 effectively achieved) - Stability: CV 1.31% (superior to mimalloc 3.50%) - Syscall budget: 1.25e-7/op (excellent) - RSS: 33MB stable, 0% drift over 60 minutes ## Files Added/Modified New boxes: - core/box/ss_mem_lean_env_box.h - core/box/ss_release_policy_box.{h,c} - core/box/alloc_passdown_ssot_env_box.h Scripts: - scripts/soak_mixed_single_process.sh - scripts/analyze_epoch_tail_csv.py - scripts/soak_mixed_rss.sh - scripts/calculate_percentiles.py - scripts/analyze_soak.py Documentation: Phase 40-60 analysis documents ## Design Decisions 1. Profile separation (core/bench_profile.h): - MIXED_TINYV3_C7_SAFE: Speed-first (no LEAN) - MIXED_TINYV3_C7_BALANCED: Balanced mode (LEAN+OFF) 2. Box Theory compliance: - All ENV gates reversible (HAKMEM_SS_MEM_LEAN, HAKMEM_ALLOC_PASSDOWN_SSOT) - Single conversion points maintained - No physical deletions (compile-out only) 3. Lessons learned: - SSOT effective only where redundancy exists (Phase 60 showed limits) - Branch prediction extremely effective (~0 cycles for well-predicted branches) - Early-exit pattern valuable even when seemingly redundant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-17 06:24:01 +09:00
#!/usr/bin/env python3
"""Analyze soak test CSV results for Phase 50."""
import sys
import csv
import statistics
def analyze_csv(filename):
"""Analyze a single CSV file and return metrics."""
throughputs = []
rss_values = []
with open(filename, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
throughput = float(row['throughput_ops_s'])
rss = float(row['peak_rss_mb'])
throughputs.append(throughput)
rss_values.append(rss)
if len(throughputs) == 0:
return None
# Calculate metrics
first_5 = throughputs[:5] if len(throughputs) >= 5 else throughputs
last_5 = throughputs[-5:] if len(throughputs) >= 5 else throughputs
first_throughput = statistics.mean(first_5)
last_throughput = statistics.mean(last_5)
throughput_drift_pct = ((last_throughput - first_throughput) / first_throughput) * 100
mean_throughput = statistics.mean(throughputs)
stddev_throughput = statistics.stdev(throughputs) if len(throughputs) > 1 else 0
cv_pct = (stddev_throughput / mean_throughput) * 100
first_rss = rss_values[0]
last_rss = rss_values[-1]
rss_drift_pct = ((last_rss - first_rss) / first_rss) * 100
peak_rss = max(rss_values)
return {
'samples': len(throughputs),
'mean_throughput': mean_throughput,
'first_throughput': first_throughput,
'last_throughput': last_throughput,
'throughput_drift_pct': throughput_drift_pct,
'stddev_throughput': stddev_throughput,
'cv_pct': cv_pct,
'first_rss': first_rss,
'last_rss': last_rss,
'peak_rss': peak_rss,
'rss_drift_pct': rss_drift_pct,
}
def main():
files = {
'hakmem FAST': 'soak_fast_5min.csv',
'mimalloc': 'soak_mimalloc_5min.csv',
'system malloc': 'soak_system_5min.csv',
}
results = {}
for name, filename in files.items():
try:
metrics = analyze_csv(filename)
if metrics:
results[name] = metrics
print(f"\n{'='*60}")
print(f"Allocator: {name}")
print(f"{'='*60}")
print(f"Samples: {metrics['samples']}")
print(f"Mean throughput: {metrics['mean_throughput']/1e6:.2f} M ops/s")
print(f"First 5 avg: {metrics['first_throughput']/1e6:.2f} M ops/s")
print(f"Last 5 avg: {metrics['last_throughput']/1e6:.2f} M ops/s")
print(f"Throughput drift: {metrics['throughput_drift_pct']:+.2f}%")
print(f"Throughput CV: {metrics['cv_pct']:.2f}%")
print(f"First RSS: {metrics['first_rss']:.2f} MB")
print(f"Last RSS: {metrics['last_rss']:.2f} MB")
print(f"Peak RSS: {metrics['peak_rss']:.2f} MB")
print(f"RSS drift: {metrics['rss_drift_pct']:+.2f}%")
except Exception as e:
print(f"Error processing {name}: {e}", file=sys.stderr)
print(f"\n{'='*60}")
print("Summary")
print(f"{'='*60}")
print(f"{'Allocator':<20} {'Throughput':>12} {'TP Drift':>10} {'CV':>8} {'Peak RSS':>10} {'RSS Drift':>10}")
print(f"{'':<20} {'(M ops/s)':>12} {'(%)':>10} {'(%)':>8} {'(MB)':>10} {'(%)':>10}")
print("-" * 80)
for name in ['hakmem FAST', 'mimalloc', 'system malloc']:
if name in results:
m = results[name]
print(f"{name:<20} {m['mean_throughput']/1e6:>12.2f} {m['throughput_drift_pct']:>10.2f} {m['cv_pct']:>8.2f} {m['peak_rss']:>10.2f} {m['rss_drift_pct']:>10.2f}")
if __name__ == '__main__':
main()