Phase 4-Step1: Add PGO workflow automation (+6.25% performance)

Implemented automated Profile-Guided Optimization workflow using Box pattern:

Performance Improvement:
- Baseline:      57.0 M ops/s
- PGO-optimized: 60.6 M ops/s
- Gain: +6.25% (within expected +5-10% range)

Implementation:
1. scripts/box/pgo_tiny_profile_config.sh - 5 representative workloads
2. scripts/box/pgo_tiny_profile_box.sh - Automated profile collection
3. Makefile PGO targets:
   - pgo-tiny-profile: Build instrumented binaries
   - pgo-tiny-collect: Collect .gcda profile data
   - pgo-tiny-build:   Build optimized binaries
   - pgo-tiny-full:    Complete workflow (profile → collect → build → test)
4. Makefile help target: Added PGO instructions for discoverability

Design:
- Box化: Single responsibility, clear contracts
- Deterministic: Fixed seeds (42) for reproducibility
- Safe: Validation, error detection, timeout protection (30s/workload)
- Observable: Progress reporting, .gcda verification (33 files generated)

Workload Coverage:
- Random mixed: 3 working set sizes (128/256/512 slots)
- Tiny hot: 2 size classes (16B/64B)
- Total: 5 workloads covering hot/cold paths

Documentation:
- PHASE4_STEP1_COMPLETE.md - Completion report
- CURRENT_TASK.md - Phase 4 roadmap (Step 1 complete ✓)
- docs/design/PHASE4_TINY_FRONT_BOX_DESIGN.md - Complete Phase 4 design

Next: Phase 4-Step2 (Hot/Cold Path Box, target +10-15%)

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-29 11:28:38 +09:00
parent 7f9e4015da
commit b51b600e8d
6 changed files with 1326 additions and 0 deletions

View File

@ -1,6 +1,40 @@
# Makefile for hakmem PoC
CC = gcc
# Default target: Show help
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "========================================="
@echo "HAKMEM Build Targets"
@echo "========================================="
@echo ""
@echo "Development (Fast builds):"
@echo " make bench_random_mixed_hakmem - Quick build (~1-2 min)"
@echo " make bench_tiny_hot_hakmem - Quick build"
@echo " make test_hakmem - Quick test build"
@echo ""
@echo "Benchmarking (PGO-optimized, +6% faster):"
@echo " make pgo-tiny-full - Full PGO workflow (~5-10 min)"
@echo " = Profile + Optimize + Test"
@echo " make pgo-tiny-profile - Step 1: Build profile binaries"
@echo " make pgo-tiny-collect - Step 2: Collect profile data"
@echo " make pgo-tiny-build - Step 3: Build optimized"
@echo ""
@echo "Comparison:"
@echo " make bench-comparison - Compare hakmem vs system vs mimalloc"
@echo " make bench-pool-tls - Pool TLS benchmark"
@echo ""
@echo "Cleanup:"
@echo " make clean - Clean build artifacts"
@echo ""
@echo "Phase 4 Performance:"
@echo " Baseline: 57.0 M ops/s"
@echo " PGO-optimized: 60.6 M ops/s (+6.25%)"
@echo ""
@echo "TIP: For best performance, use 'make pgo-tiny-full'"
@echo "========================================="
CXX = g++
# Directory structure (2025-11-01 reorganization)
@ -1262,3 +1296,58 @@ test_simple_e1: test_simple_e1.o $(HAKMEM_OBJS)
test_simple_e1.o: test_simple_e1.c
$(CC) $(CFLAGS) -c -o $@ $<
# ========================================
# Phase 4: PGO (Profile-Guided Optimization) Targets
# ========================================
# Phase 4-Step1: PGO Profile Build
# Builds binaries with -fprofile-generate for profiling
.PHONY: pgo-tiny-profile
pgo-tiny-profile:
@echo "========================================="
@echo "Phase 4: Building PGO Profile Binaries"
@echo "========================================="
$(MAKE) clean
$(MAKE) PROFILE_GEN=1 bench_random_mixed_hakmem bench_tiny_hot_hakmem
@echo ""
@echo "✓ PGO profile binaries built"
@echo "Next: Run 'make pgo-tiny-collect' to collect profile data"
@echo ""
# Phase 4-Step1: PGO Profile Collection
# Executes representative workloads to generate .gcda files
.PHONY: pgo-tiny-collect
pgo-tiny-collect:
@echo "========================================="
@echo "Phase 4: Collecting PGO Profile Data"
@echo "========================================="
./scripts/box/pgo_tiny_profile_box.sh
# Phase 4-Step1: PGO Optimized Build
# Builds binaries with -fprofile-use for optimization
.PHONY: pgo-tiny-build
pgo-tiny-build:
@echo "========================================="
@echo "Phase 4: Building PGO-Optimized Binaries"
@echo "========================================="
@echo "Building optimized binaries..."
$(MAKE) clean
$(MAKE) PROFILE_USE=1 bench_random_mixed_hakmem bench_tiny_hot_hakmem
@echo ""
@echo "✓ PGO-optimized binaries built"
@echo "Next: Run './bench_random_mixed_hakmem 1000000 256 42' to test"
@echo ""
# Phase 4-Step1: Full PGO Workflow
# Complete workflow: profile → collect → build → test
.PHONY: pgo-tiny-full
pgo-tiny-full: pgo-tiny-profile pgo-tiny-collect pgo-tiny-build
@echo "========================================="
@echo "Phase 4: PGO Full Workflow Complete"
@echo "========================================="
@echo "Testing PGO-optimized binary..."
@echo ""
./bench_random_mixed_hakmem 1000000 256 42
@echo ""
@echo "✓ PGO optimization complete!"
@echo ""