Iterative or Innovative? A Problem-Oriented Perspective for Code Optimization

Tong Ye, Tengfei Ma, Lingfei Wu, Xuhong Zhang, Shouling Ji, Wenhai Wang · DOI

TL;DR

This paper introduces a "problem-oriented" approach to code optimization using Large Language Models (LLMs), moving beyond single-programmer iterative improvements to leverage diverse solutions from multiple programmers. They also propose an "anchor verification framework" to combat the "optimization tax" (performance gains at the cost of correctness), significantly boosting optimization ratio, speedup, and correctness.

What Problem Does This Paper Address?

While LLMs excel at code generation, their potential for optimizing code for performance, specifically execution time, is less explored. Existing methods often rely on datasets of iterative code improvements from a single programmer. This "user-oriented" approach leads to incremental, local optimizations, missing out on more significant, global algorithmic innovations that arise from diverse perspectives. Furthermore, LLM-generated optimized code can sometimes sacrifice correctness for speed – an "optimization tax." This paper aims to address both the limited scope of current optimization datasets and the correctness issue in LLM-based code optimization.

Methods

The core innovation is the Problem-Oriented Perspective. Instead of using optimization pairs from a single programmer's iterative submissions, they aggregate solutions from multiple programmers for the same problem. These diverse solutions are then ordered by runtime to create new optimization trajectories. This approach aims to capture broader algorithmic improvements.

To tackle the "optimization tax," they introduce the Anchor Verification Framework. This framework leverages the "slow but correct" original code as a trusted anchor. It involves three stages:

  1. Test Input Generation: The LLM explains the slow code and generates test case inputs.
  2. Verified Testcase Construction: These inputs are run against the slow code to generate correct outputs, forming verified test cases.
  3. Iterative Refinement: The optimized code is then refined using these verified test cases to ensure correctness.

Datasets

The paper utilizes and extends the PIE (Program Improvement Examples) dataset. They create a new dataset called PCO (Problem-oriented Code Optimization) by applying their problem-oriented perspective to existing code optimization datasets. This PCO dataset aims to provide richer, more diverse optimization pairs.

Key Insights and Ideas

  • Diversity is Key: Aggregating solutions from multiple programmers (problem-oriented) leads to significantly better optimization than relying on a single programmer's iterative improvements (user-oriented). This mirrors real-world collaborative code development.
  • Global vs. Local: The problem-oriented approach encourages and captures "global algorithmic optimizations" (major changes to the algorithm) more effectively than the user-oriented approach, which tends to focus on "local optimizations" (minor code tweaks).
  • The "Optimization Tax" is Real: LLMs can produce faster code that is functionally incorrect. This trade-off is a significant challenge.
  • Anchor Verification Works: Using the original, slow-but-correct code as a verification anchor is a robust way to ensure the correctness of optimized code, mitigating the "optimization tax."
  • Data Efficiency: The problem-oriented perspective can alleviate data scarcity issues, as fewer optimization pairs from this approach can yield competitive or superior results compared to larger user-oriented datasets.

Key Results

  • Adapting LLMs to problem-oriented optimization pairs significantly improved optimization ratios (e.g., 31.24% to 58.90%) and speedup (e.g., 2.95x to 5.22x) compared to user-oriented pairs.
  • The Anchor Verification Framework further boosted performance, achieving up to 71.06% %OPT, 6.08x SPEEDUP, and 74.54% CORRECTNESS with DEEPSEEK-V3, outperforming baseline methods like Self-Debugging and Direct Test Generation.
  • The framework demonstrated generalizability across languages (C/C++ and Python) and hardware.
  • Human analysis showed that problem-oriented pairs are more likely to involve "global algorithmic optimizations."

Limitations and Future Work

  • Focus on Time: The paper primarily focuses on optimizing for execution time, not other optimization directions like memory usage.
  • "Compiled, but semantically wrong" failures: A significant portion of optimization failures (53%) are due to semantic errors, indicating LLMs still struggle with fully capturing high-level program intent.
  • Persistent Errors: While the Anchor Verification Framework substantially reduces errors, it doesn't eliminate them entirely, leaving "zero-correctness-loss optimization" as an open challenge.
  • Future Work: The authors suggest exploring other optimization directions and further investigating how to address semantic errors more effectively. They also propose extending the problem-oriented perspective and anchor verification to more complex real-world scenarios like microservice architectures and large-scale codebases.

Summary updated

Abstract

Large language models (LLMs) have shown remarkable capabilities in solving various programming tasks, such as code generation. However, their potential for code optimization, particularly in performance enhancement, remains largely unexplored. This paper investigates the capabilities of LLMs in optimizing code for minimal execution time, addressing a critical gap in current research. The recently proposed code optimization dataset constructs program optimization pairs based on iterative submissions from the same programmer for the same problem. However, this approach limits LLMs to local performance improvements, neglecting global algorithmic innovation. To overcome this limitation, we adopt a completely different perspective by reconstructing the optimization pairs into a problem-oriented approach. This allows for the integration of various ideas from multiple programmers tackling the same problem. Experimental results demonstrate that adapting LLMs to problem-oriented optimization pairs significantly enhances their optimization capabilities. Furthermore, recognizing the inherent trade-offs in code optimization, we introduce an anchor verification mechanism to mitigate the "optimization tax". Ultimately, our approach elevates both the optimization ratio and speedup to new levels.
BibTeX
@inproceedings{ye2026iterative,
  author = {Tong Ye and Tengfei Ma and Lingfei Wu and Xuhong Zhang and Shouling Ji and Wenhai Wang},
  title = {{Iterative or Innovative? A Problem-Oriented Perspective for Code Optimization}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=HGaUV3jjvo},
}
Figure