Introduction
Code optimization is the critical process of transforming software to enhance performance—such as reducing execution time or memory footprint—while strictly maintaining functional correctness. Historically, this task has transitioned from manual expert tuning to automated compiler heuristics. While classical Machine Learning (ML) and Deep Learning (DL) have been applied to this domain, they often struggle with the intricate semantic structures inherent in source code.
The emergence of Large Language Models (LLMs) presents a paradigm shift, offering neural "optimizers" capable of reasoning about program logic. This paper provides the first systematic literature review (SLR) of LLMs applied specifically to code optimization, analyzing 53 primary studies to map the current landscape and identify remaining hurdles.
Methodology and Taxonomy
The authors followed established software engineering guidelines for their SLR, filtering thousands of candidates to select 53 core studies. These studies were categorized using a multi-dimensional taxonomy organized around four primary Research Questions (RQs).
The taxonomy examines:
- Model Roles: Beyond direct optimization, LMs serve as generators, evaluators (predicting performance gains), and preprocessors (inferring types or explaining logic).
- Techniques: Approaches include model-based fine-tuning, advanced prompt engineering (e.g., Chain-of-Thought), and problem reformulation (e.g., Reinforcement Learning).
- Training Paradigms: The study compares the utility of massive general-purpose models (like GPT-4) against smaller, code-specialized architectures (like CodeLLaMA).
Data Landscape
A significant finding is the reliance on specific dataset classes. While competitive programming benchmarks (HumanEval, MBPP) are common, they often lack real-world complexity. Performance-specific benchmarks like PIE and EffiBench are emerging as foundational. However, a critical gap exists: 68% of studies utilize synthetic data, while only 9% evaluate on full-scale, industrial software projects.
Key Insights and Trends
Generalists vs. Specialists
Contrary to expectations, general-purpose models like GPT-4 are utilized more frequently (61 instances) than code-specialized models (43 instances). Their superior instruction-following and reasoning capabilities often outweigh the benefits of domain-specific pre-training.
Iterative Refinement
LLMs rarely achieve optimal results in a single pass. The most effective systems implement feedback loops where the model generates code, an external compiler or profiler executes it, and the resulting performance metrics are fed back to the model for iterative improvement.
The Language Bias
Current research is heavily skewed toward Python (81% of studies). This leaves a significant opportunity for cross-lingual optimization research—transferring performance patterns learned in low-level languages like C++ to higher-level languages.
Challenges and Future Directions
Despite the promise of LLMs, several barriers to production deployment remain:
- Reliability: The "hallucination" of incorrect code is unacceptable in mission-critical systems.
- Efficiency: The computational cost of running massive models can sometimes exceed the energy savings gained from the optimization itself.
- Multi-objective Optimization: Most current work focuses on a single metric (usually execution time), ignoring the trade-offs between speed, memory usage, and power consumption.
The authors advocate for "agentic" workflows, where LMs act as autonomous agents interacting with IDEs and profilers to verify their own suggestions, ensuring both performance gains and functional integrity.
Summary updated