Introduction
Modern Large Language Models (LLMs) excel at generating functionally correct code but often struggle with performance optimization. Writing code that is both correct and efficient is critical for scalable software, yet models frequently treat optimization as a "black box," leading to transformations that may actually degrade runtime performance. This is primarily due to the scarcity of high-quality datasets showing explicit "slow-to-fast" transformations and a lack of structured reasoning in current optimization tasks.
PerfCoder addresses these challenges by introducing a family of LLMs specifically engineered for interpretable code optimization. By combining "strategy-aware" supervised fine-tuning with reinforcement learning based on actual runtime measurements, PerfCoder achieves state-of-the-art speedups.
Methodology: Strategy-Aware Optimization
The researchers developed a multi-stage pipeline to train PerfCoder, focusing on making the optimization process transparent and reasoned.
The pipeline consists of four key components:
- Automated Strategy Synthesis: A 32B model analyzes "slow-fast" code pairs to extract optimization strategies across 15 canonical categories, such as Loop Efficiency and I/O Throughput Optimization.
- Balanced Strategy Sampling: A rarity-weighted scoring system ensures the training data includes diverse techniques, preventing the model from over-focusing on simple fixes.
- Single-Step Supervised Fine-Tuning (SFT): The model is trained to generate a structured
[Strategy] -> [Optimized Code]sequence, forcing it to plan before implementation. - Reinforcement Fine-Tuning (GRPO): Using Group Relative Policy Optimization, the model's "Planner Mode" is refined. It generates strategies implemented by an external optimizer, with rewards based on actual runtime speedup.
Datasets and Evaluation
PerfCoder was trained and evaluated using:
- PIE (Program Iterative Evolution): A reconstructed corpus of 30,649 slow-fast program pairs, utilizing "Global-best replacement" to ensure learning from optimal solutions.
- PolyBenchC: A suite of 30 numerical kernels used to test the model's ability to transfer optimization skills to new domains.
Key Insights: Planning Over Scaling
A major finding of this research is that performance optimization is not merely a scaling problem. A 7B PerfCoder model outperformed much larger models because it was specifically trained to understand optimization strategies. Furthermore, small models (1.5B or 7B) can act as effective "planners" for larger models. When PerfCoder provided the strategy, GPT-5's speedup jumped from 1.96x to 4.82x.
The authors also noted that high code accuracy (passing tests) does not necessarily correlate with effective optimization. Many models can make code work, but making it fast requires a distinct set of skills that PerfCoder explicitly targets.
Experimental Results
PerfCoder-QC (7B) achieved a state-of-the-art 2.50x runtime speedup on the PIE benchmark, surpassing both PIE-CodeLlama (1.89x) and GPT-5 (1.96x) in single-step mode.
In cooperative workflows, a 1.5B PerfCoder guiding GPT-5 achieved a 4.82x speedup with a 79.86% effective optimization rate. The model also demonstrated strong transferability, maintaining its lead on the PolyBenchC scientific kernels.
Limitations and Future Work
Current limitations include a dependency on the quality of the strategy extractor model and a primary focus on C++. Future work will explore using stronger frontier models for data synthesis, expanding support to languages like Python and Java, and incorporating hardware-specific awareness to tailor optimizations for different CPU/GPU architectures.
Summary updated