Efficiency Hallucination: Every Model Rewrote Code That Couldn't Get Faster
Okay, this is going to sound dumb, but I spent Sunday evening asking three different models to make a function faster that could not be made faster, and every single one of them did it anyway. Confidently. With a comment at the top explaining the speedup. The function was a two-pointer sweep over a sorted list. It's O(n), it touches each element once, and I had already benchmarked it. I pasted it…
A Columbia University study published on arXiv in September reveals a phenomenon known as "Efficiency Hallucination" in large language models (LLMs) when asked to optimize code. Researchers Sarah Wilson, Gail Kaiser, and Patrick Musau tested nine models from Claude, GPT, and Gemini families on five problems from EffiBench. They paired the top-performing human solutions with deliberately degraded versions and asked the models to optimize both.
Under a standard prompt, all nine models rewrote the already optimal code without fail. The researchers dubbed this behavior "the Evaluation Trap," as every benchmark a model has been trained on rewards producing an edit, even if it's unnecessary. To combat this, the authors introduced a simple intervention: instruct the models to only suggest an edit if they are 90% confident it improves execution speed; otherwise, they should output "ALREADY_OPTIMAL."
This resulted in a significant decrease in over-editing on optimal code, from 100% to 55.6%. However, the models still overestimated their confidence level, reporting 90% even when they were unsure, which is a common overconfidence problem. The researchers note that the true solution lies in actual performance testing rather than just code optimization.
They also found a "Capability-Calibration Inversion," where better-performing models were often worse at recognizing when no optimization is needed. The study highlights the importance of evaluating not just the models' ability to optimize code but also their calibration in determining when a code snippet is already optimal.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.