Abstract
Large Language Models (LLMs) generate functionally correct solutions but often fall short in code efficiency, a critical bottleneck for real-world deployment. In this paper, we introduce a novel test-time iterative optimization framework to address this, employing a closed-loop system where LLMs iteratively refine code based on empirical performance feedback from an execution sandbox. We explore three training strategies: Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), and Group Relative Policy Optimization (GRPO). Experiments on our Venus dataset and the APPS benchmark show that SFT and DPO rapidly saturate in efficiency gains. In contrast, GRPO, using reinforcement learning (RL) with execution feedback, continuously optimizes code performance, significantly boosting both pass@1 (from 47% to 62%) and the likelihood of outperforming human submissions in efficiency (from 31% to 45%). Our work demonstrates effective test-time code efficiency improvement and critically reveals the power of RL in teaching LLMs to truly self-improve code efficiency.
Introduction
In the current landscape of software engineering, Large Language Models (LLMs) have demonstrated a remarkable ability to achieve "functional correctness." However, correctness is only half the battle. In production environments, code that is logically sound but computationally expensive leads to inflated infrastructure costs and poor user experiences. Current LLMs, primarily trained on datasets where correctness is the dominant signal, tend to produce "naive" solutions—code that passes tests but lacks algorithmic optimization.
Previous attempts to address this through simple prompting or standard fine-tuning often hit a performance plateau. This paper introduces Afterburner, a framework designed to move beyond mere correctness by teaching models to iteratively self-improve their code's speed and memory usage through Reinforcement Learning (RL).
The Afterburner Framework
The core of our approach is the Iterative Optimization Framework (IOF), which transforms code generation from a single-shot task into a closed-loop refinement process. The framework consists of two primary components:
- Afterburner: An LLM-based "optimizer" that receives an initial code implementation and attempts to rewrite it for enhanced efficiency based on specific instructions.
- Monolith: A high-fidelity execution sandbox that executes the generated code, verifies its functional correctness against test cases, and provides precise empirical metrics, including runtime and peak memory usage.
By coupling the optimizer with the sandbox, the model receives direct feedback on whether its proposed optimizations actually result in performance gains in a real-world execution environment.
Training Strategies and the Venus Dataset
We evaluated three distinct training strategies for the Afterburner model:
- Supervised Fine-Tuning (SFT): The model is trained to mimic human-optimized code pairs.
- Direct Preference Optimization (DPO): The model is trained on pairs of "better" versus "worse" code implementations.
- Group Relative Policy Optimization (GRPO): An online RL approach that allows the model to explore various optimization pathways. GRPO rewards the model for improving efficiency while penalizing it for breaking functionality or increasing resource consumption.
To rigorously test these strategies, we introduced the Venus dataset, a benchmark comprising 8,598 tasks across five programming languages (Python, C++, Go, Java, and JavaScript). Unlike existing benchmarks, Venus includes an average of 106.6 human solutions per task, allowing us to measure model performance using percentile ranking against human developers.
Results: The Power of Reinforcement Learning
Our experiments reveal a significant divergence between traditional fine-tuning and RL-based optimization. While SFT and DPO models show initial improvements, they quickly saturate. These models tend to learn superficial "tricks" rather than deep algorithmic improvements.
In contrast, the GRPO-trained Afterburner demonstrates continuous, monotonic improvement over multiple iterations. By interacting with the Monolith sandbox, the RL agent develops an adaptive proficiency, learning to explore the solution space and discover highly optimized implementations that may differ significantly from typical human approaches.
On the Venus benchmark, the RL-powered Afterburner improved Pass@1 correctness from 47% to 62%. More importantly, the likelihood of the model outperforming human submissions in overall efficiency (the "integral" of time and memory) jumped from 31% to 45%. Notably, a 3B parameter model tuned with Afterburner-GRPO was able to rival or exceed the efficiency of much larger closed-source models like GPT-4o.
Conclusion
Afterburner demonstrates that Reinforcement Learning with execution feedback is a superior paradigm for code efficiency optimization compared to supervised methods. By shifting from mimicry to exploration, LLMs can learn to truly self-improve. While iterative optimization introduces additional test-time computation, the resulting gains in code efficiency provide substantial long-term value for production-scale software systems. Future work will explore extending this framework to complex, multi-file software projects and broader system-level optimizations.
Summary updated