TLDR: ECO (Enhanced Code Optimization) is a new framework that significantly improves the ability of code-LLMs to optimize code for runtime performance. Unlike previous methods that rely on slow-fast code pairs, ECO distills explicit Runtime Optimization Instructions (ROIs) and combines them with a symbolic bottleneck diagnosis to create ‘performance-aware prompts’. This model-agnostic approach requires no fine-tuning and has demonstrated speedups of up to 7.81x with minimal correctness loss, making code optimization more effective and practical for various LLMs.
Optimizing code for faster execution is a fundamental challenge in software engineering. While large language models (LLMs) for code have shown impressive capabilities in generating functionally correct code, making that code run faster requires a deeper understanding of performance trade-offs. Traditional methods often fall short in addressing complex, program-level bottlenecks like algorithmic restructuring or data-structure selection. Existing LLM-based approaches, which typically rely on providing examples of slow and fast code pairs, tend to encourage superficial pattern imitation rather than genuine performance reasoning, often leading to suboptimal results.
A new framework called ECO, or Enhanced Code Optimization, addresses these limitations by introducing a performance-aware prompting approach for code-LLMs. Instead of just showing slow-fast code examples, ECO provides explicit, actionable guidance tailored to the input code, helping LLMs understand the ‘why’ behind performance improvements.
How ECO Works
ECO operates through a clever, multi-step process:
First, it distills what are called Runtime Optimization Instructions (ROIs) from a large collection of reference slow-fast code pairs. Each ROI is a clear explanation of why a piece of code is inefficient and the rationale behind the changes that make it faster. These ROIs form a valuable knowledge base.
When a new piece of code needs optimizing, ECO employs two complementary modules in parallel:
1. Symbolic Advisor: This module acts like a detective, using rule-based analysis to examine the input code’s structure. It deterministically identifies specific inefficiencies and provides a ‘bottleneck diagnosis’ – pinpointing exactly where the performance issues lie and what kind of transformation is needed. For example, it might detect a recursive function that recomputes the same values repeatedly without memoization, or an unnecessary use of a dynamic data structure when a fixed-size array would be more efficient.
2. ROI Retriever: This module searches the distilled ROI database for instructions relevant to the input code’s performance characteristics. Unlike older methods that just look for similar code snippets, ECO’s retriever focuses on matching the underlying performance problems and their solutions. It returns not just example code pairs, but also the explicit ROIs that explain the optimization intent.
These two outputs – the precise bottleneck diagnosis from the Symbolic Advisor and the context-aware ROIs from the Retriever – are then combined into a ‘performance-aware prompt’. This prompt provides clear, actionable guidance that code-LLMs can directly use to rewrite the code for better performance, without needing any special fine-tuning or model-specific adaptations.
Also Read:
- Optimizing LLM Code Translation for Longer Programs with Identifier Replacement
- Optimizing LLM Workflows by Understanding Failure Patterns
Key Advantages and Performance
ECO’s design offers several significant benefits. It is ‘model-agnostic’, meaning it can be easily integrated with any code-LLM by simply prepending its guidance to the model’s input prompt. This eliminates the need for costly fine-tuning or retraining, making it highly practical for various systems, including closed-source LLMs.
Empirical studies have shown that ECO prompting dramatically improves code-LLMs’ ability to generate efficient code. It has achieved speedups of up to 7.81 times while maintaining high correctness. For instance, on a model like GPT-o4-mini, standard prompting yielded only a 1.99x speedup, whereas ECO boosted it to an impressive 7.81x – nearly a four-fold gain.
The framework also demonstrates strong generalizability, performing effectively across different scales of LLMs and even on ‘out-of-distribution’ datasets, where the problems’ characteristics differ from the data ECO was initially trained on. This robustness highlights ECO’s ability to provide reliable guidance in diverse and challenging optimization scenarios.
In conclusion, ECO represents a significant step forward in code optimization by moving beyond simple code examples. By distilling explicit optimization knowledge and providing tailored, performance-aware prompts, it empowers code-LLMs to reason about and implement genuine performance improvements, making code faster and more efficient. You can read the full research paper for more details here.


