LLM Program Optimization via Retrieval Augmented Search

Sagnik Anupam, Alexander Shypula, Osbert Bastani


Abstract
Recent work has demonstrated the potential of large language models (LLMs) for program optimization, a key challenge in programming languages. We propose a blackbox adaptation method called Retrieval Augmented Search (RAS) that performs beam search over candidate optimizations; at each step, it retrieves in-context examples from a given training dataset of slow-fast program pairs to guide the LLM. Critically, we find that performing contextual retrieval based on an LLM-generated natural language description significantly outperforms retrieval based on the source code. We also propose AEGIS, a method for improving interpretability by decomposing training examples into "atomic edits” that are significantly more incremental in nature. We show that RAS performs up to 2.06× better than prior state-of-the-art blackbox adaptation strategies on optimizing C++ programs, and that AEGIS performs up to 1.37× better while making significantly smaller edits. We also show that using RAS improves the mean runtime percentile of Python programs by 10.27 compared to baselines.
Anthology ID:
2026.findings-acl.2092
Volume:
Findings of the Association for Computational Linguistics: ACL 2026
Month:
July
Year:
2026
Address:
San Diego, California, United States
Editors:
Maria Liakata, Viviane P. Moreira, Jiajun Zhang, David Jurgens
Venue:
Findings
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
42170–42186
Language:
URL:
https://preview.aclanthology.org/ingest-acl/2026.findings-acl.2092/
DOI:
Bibkey:
Cite (ACL):
Sagnik Anupam, Alexander Shypula, and Osbert Bastani. 2026. LLM Program Optimization via Retrieval Augmented Search. In Findings of the Association for Computational Linguistics: ACL 2026, pages 42170–42186, San Diego, California, United States. Association for Computational Linguistics.
Cite (Informal):
LLM Program Optimization via Retrieval Augmented Search (Anupam et al., Findings 2026)
Copy Citation:
PDF:
https://preview.aclanthology.org/ingest-acl/2026.findings-acl.2092.pdf
Checklist:
 2026.findings-acl.2092.checklist.pdf