Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimization

Mingzhe Du, Anh Tuan Luu, Yue Liu, Yuhao Qing, Dong Huang, Xinyi He, Qian Liu, Zejun Ma, See-Kiong Ng

TL;DR

While Large Language Models (LLMs) are increasingly adept at writing code that works, they are notoriously bad at writing code that is fast. Afterburner introduces a novel reinforcement learning framework that uses a closed-loop execution sandbox to iteratively refine code. This approach boosts computational efficiency to the point where the AI frequently outperforms human-written solutions.

What Problem Does This Paper Address?

In the world of software engineering, "functional correctness"—whether the code passes its unit tests—is only half the battle. The other half is "computational efficiency," which dictates how much time and memory the code consumes. Current LLMs are trained primarily on correctness, often producing naive, brute-force solutions that are computationally expensive. This is a major bottleneck for real-world production systems where latency and cloud computing costs are paramount.

Existing attempts to fix this usually involve simple fine-tuning on datasets of "better" code. However, these models often just memorize superficial patterns (like swapping a loop for a built-in function) without truly understanding the underlying algorithmic trade-offs. The authors of Afterburner set out to bridge this gap by creating a system that learns from empirical, real-world performance feedback rather than static examples.

Methods: The Iterative Optimization Framework

The researchers developed the Iterative Optimization Framework (IOF) to facilitate test-time code improvement. The framework consists of two main components working in tandem:

  1. Afterburner: An LLM "optimizer" (based on Qwen 2.5 3B) that analyzes existing code and suggests efficiency improvements.
  2. Monolith: A high-fidelity execution sandbox that runs the generated code against test cases, measuring actual runtime and memory usage to provide empirical feedback.
The Iterative Optimization Framework (IOF) featuring the Afterburner LLM and Monolith execution sandbox.

The core innovation lies in the training strategy used for the Afterburner model. While the team tested standard Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO), the standout performer was Group Relative Policy Optimization (GRPO).

Unlike SFT, which simply tells the model to "copy this better code," GRPO leverages Reinforcement Learning (RL). The model generates a group of different solutions, executes them in the Monolith sandbox, and receives a reward based on which versions were the fastest and most memory-efficient. This allows the model to explore the "solution space" and discover novel algorithmic optimizations that weren't necessarily present in its training data.

Datasets

To train and evaluate the system, the researchers utilized two primary datasets:

  • Venus (New): A massive new multilingual benchmark created specifically for this research. It contains over 8,500 tasks across six languages (Python, C++, Go, Java, JavaScript, and Rust). Crucially, it includes an average of 106 human solutions per task, allowing the researchers to calculate an "efficiency percentile" for the AI's code compared to human efforts.
  • APPS: A widely recognized benchmark for code generation, used here to test how well the model generalizes to "out-of-distribution" problems.

Key Insights and Ideas

  • The SFT Plateau: Supervised learning (SFT) and preference matching (DPO) gains saturate almost immediately. Once the model learns basic syntax tricks, it stops improving its algorithmic efficiency.
  • RL as an "Adaptive" Teacher: GRPO doesn't just mimic; it develops "adaptive proficiency." Because it sees the actual execution time of its own creations, it can refine its strategy over multiple iterations, continuing to find gains where other methods flatline.
  • Correctness First: The authors found that rewards must be heavily weighted toward functional correctness. If the reward for speed is too high, the model "cheats" by writing broken code that finishes instantly because it crashes.
  • Beyond Human Mimicry: Perhaps most surprisingly, the RL-trained model often discovered implementations that were structurally different from canonical human approaches, proving it wasn't just copying human "best practices" but actually optimizing for the hardware.

Key Results

The empirical results demonstrate a clear and compounding "Afterburner" effect when using Reinforcement Learning:

Performance comparison between Reinforcement Learning (GRPO) and Supervised Fine-Tuning (SFT) over multiple optimization iterations, alongside a code optimization example.
  • Correctness Boost: On the Venus benchmark, the model’s Pass@1 (the chance of the first attempt being functionally correct) jumped significantly from 47% to 62%.
  • Beating Humans: The likelihood of the model outperforming human-submitted solutions in overall efficiency rose from 31% to 45%.
  • Iterative Success: While SFT models stopped improving after one or two tries, the GRPO-trained Afterburner showed sustained, linear improvement over 10 optimization iterations, consistently squeezing out more performance with each pass.

Limitations and Future Work

Despite the impressive gains, the authors acknowledge several hurdles that remain for test-time code optimization:

  • Inference Overhead: Iterative optimization is "test-time heavy." Calling an LLM and running a sandbox ten times is computationally much more expensive than a single-pass generation.
  • Complexity Limits: The current framework excels at algorithmic, competition-style tasks (like those in LeetCode or APPS). Extending this to massive, real-world software projects with complex library dependencies and I/O operations remains a significant challenge.
  • Credit Assignment: In a multi-turn conversation, it is still difficult for the model to pinpoint exactly which change in a long history of edits led to a specific performance gain.

Future work will likely focus on making these iterations more computationally efficient and expanding the "Monolith" sandbox to handle more complex, multi-file software environments.

Summary updated

BibTeX
@inproceedings{du2025afterburner,
  author = {Mingzhe Du and Anh Tuan Luu and Yue Liu and Yuhao QING and Dong HUANG and Xinyi He and Qian Liu and Zejun MA and See-Kiong Ng},
  title = {{Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=At8OUlyTOu},
}
Figure