Reinforcement Learning for Code Optimization
cs.LG, cs.AI
Submitted: 2026-07-28
Updated: 2026-10-07
Comments: 126 pages
Code: https://github.com/containers/bubblewrap
License: http://creativecommons.org/licenses/by/4.0/
The gist: RL for code correctness is now established: have the model generate a program, run it against hidden test cases, and reward solutions that pass.
Terminology
Abstract
RL for code correctness is now established: have the model generate a program, run it against hidden test cases, and reward solutions that pass. Extending this to code optimization seems straightforward: just add execution time to the reward. But in practice, once timing drives the reward, small problems in measurement noise, reward sparsity, or GRPO instability overwhelm the signal and make RL fail: generated solutions are barely faster, and more of them can fail. We make execution time learnable through three stages: (1) how code is tested, by building DMC-Optim with large optimization tests and a calibrated sandbox; (2) how speed is turned into reward, by composing correctness and speed in the RL environment and using an offline simulator to predict the most promising configurations; and (3) how the model learns from that reward, by adapting GRPO and evaluation to the sparser, noisier timed-execution setting. On DMC-Optim, the strongest optimization-aware configurations improve strict top-50% pass@1 from 18.0% to 31.3% on Qwen 2.5 7B and from 30.7% to 50.4% on CWM 32B. These gains further increase at stricter percentiles such as top-30%, with 125% relative improvement for CWM 32B, while preserving pure-correctness scores. When the timing sandbox is degraded, robust optimization RL reaches 100% to 200% improvement over standard RLVR, depending on the evaluation criterion. On LCB, CWM 32B wins up to 83% of median-sample speed comparisons against standard RLVR. Relative to the fastest correct human submissions per problem, it reaches about half the human rate of complexity-class improvements (13% vs. 22%).
Sources
- Evaluating Large Language Models Trained on Code
- Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimization
- CWM: An Open-Weights LLM for Research on Code Generation with World Models
- Search-Based LLMs for Code Optimization
- DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning
- On-Policy RL with Optimal Reward Baseline
- SWE-Perf: Can Language Models Optimize Code Performance on Real-World Repositories?
- EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning
- LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code
- All-Quadrant Bounded Clipping GRPO: Closing the Unbounded Blind Spot for Stable and Generalizable Training
- Evaluating Language Models for Efficient Code Generation
- Understanding R1-Zero-Like Training: A Critical Perspective
- SWE-fficiency: Can Language Models Optimize Real-World Repositories on Real Workloads?
- Improving HPC Code Generation Capability of LLMs via Online Reinforcement Learning with Real-Machine Benchmark Rewards
- AIMO-2 Winning Solution: Building State-of-the-Art Mathematical Reasoning Models with OpenMathReasoning dataset
- Performance-Aligned LLMs for Generating Fast Code
- AlphaEvolve: A coding agent for scientific and algorithmic discovery
- gpt-oss-120b & gpt-oss-20b Model Card
- MaxCode: A Max-Reward Reinforcement Learning Framework for Automated Code Optimization
- COFFE: A Code Efficiency Benchmark for Code Generation
Related papers
- Polynomial-Augmented Neural Networks (PANNs) with Weak Orthogonality Constraints for Enhanced Function and PDE Approximation
- AIRL-S: Unifying Reinforcement Learning and Search-Based Test-Time Scaling via Adversarial Inverse Reinforcement Learning
- Transformers as Bayesian In-Context Experimenters: Smoothness-Adaptive Efficient ATE Estimation
- Convergence issues in Relational Concept Analysis based on AOC-posets
- Beliefs Beyond Posteriors: The Predictive Cost of ELBO Binding
- Understanding Diffusion Models via Ratio-Based Function Approximation with SignReLU Networks