LLMs and the Limits of Automated Code Optimization

2025-01-07

David Andersen experimented with using Large Language Models (LLMs) to optimize code that finds the difference between the smallest and largest numbers whose digits sum to 30 in a list of a million random integers. Initial Python and Rust code ran slowly. While the LLM improved parts, such as the digit summing function, it missed a crucial optimization: checking if a number is relevant *before* the expensive digit sum calculation. Manual intervention, involving a faster random number generator, parallelization, and preprocessing, sped up the Rust code by a factor of 55. This highlights LLMs' limitations in code optimization, particularly for complex problems demanding deep algorithmic understanding and parallelization strategies. Human ingenuity remains crucial.

Development Performance