Refactoring 09: Performance and Bottlenecks
Goal
Find hotspots with profiling and apply small, safe optimizations.
Sequence
- •Order: 09
- •Previous: refactoring-08-experiment-tracking
- •Next: refactoring-10-security-privacy
Workflow
- •Reproduce a slow path with a small, representative dataset.
- •Success: A repeatable slow case is identified.
- •Profile with a basic tool (cProfile, pyinstrument, or line_profiler).
- •Success: Hotspots are measured and recorded.
- •Apply minimal fixes (vectorization, caching, avoiding repeated IO).
- •Success: Targeted code changes are implemented.
- •Re-measure and record before/after metrics.
- •Success: Performance improvement is quantified.
- •Keep optimizations local and reversible.
- •Success: Changes are isolated and easy to revert.
Guardrails
- •Avoid algorithm changes unless requested.
- •Do not optimize without measurements.
- •Keep performance work separate from refactor-only changes.