Technical Optimizations on Textbook-Efficient Code with LLMs
Year: 2026
Type: conference-paper
Abstract: Runtime efficiency is an important attribute of source code, typically improved through high-level algorithm selections or low-level implementation optimizations. While algorithmic efficiency is well studied and formally taught, technical optimization on implementation details relies heavily on tacit, experience-driven knowledge that is often inaccessible to novices. To examine this assumption, we prompted six LLMs to optimize 649 student programs that were already efficient by textbook standards. Among the LLM-generated outputs that preserved the original functionality, \(34\%\) achieved non-trivial runtime improvements, with an average execution time reduction of \(18.9\%\) and a corresponding speedup of 1.3 ×. This finding indicates a potential gap between being textbook-efficient and being practically efficient . Our qualitative analysis further reveals both the strengths and limitations of applying LLMs to technical optimizations. On the positive side, LLMs propose more efficient APIs, lightweight data structures, and mathematical simplifications. On the downside, LLMs may misinterpret requirements, introduce redundant computations, or overcomplicate logic, resulting in test failures ( \(33\%\) ) or performance regressions ( \(9\%\) ). Overall, our study demonstrates the potential of LLMs to optimize textbook-efficient code. It also highlights, however, that reliable application with current models still requires rigorous verification and careful integration.
Authors: Hanrui Qi, Yida Tao
Institution: Southern University of Science and Technology
Language: English
Subfield: Information Systems
Field: Computer Science
Domain: Physical Sciences
Open Access status: hybrid
Award: G4012627582
OpenAlex ID: W7212045345
