Skip to main content
Lightning Jar - Web Studio Lightning Jar Wordmark
Reading List

The Economic Benefit of Refactoring

Summary:

Giles Edwards-Alexander built a 150,000-line application entirely with coding agents, then refactored its bloated 17,155-line data access layer through fifteen steps of Fowler-discipline refactoring, measuring agent token consumption before and after. Implementing the identical feature dropped from 159,564 input tokens to 27,360, an 83 percent reduction, at an upfront refactoring cost of roughly five million tokens. Two caveats carry as much weight as the headline. The agents could not select which refactorings to apply; every step needed human judgment. And agents show no learning across sessions, so each fresh session pays the full price of the code as it finds it, which is exactly why refactoring pays compound returns: the structure IS the context. This lands squarely on our own research program's central finding from a different direction: what an agent costs is determined by what you hand it, and a well-factored codebase is to a coding agent what a curated index is to a site agent. The payback math depends on change frequency, and it is one experiment on one codebase, but the direction of the result matches everything we have measured.

Excerpt:

"A controlled experiment: fifteen disciplined refactoring steps cut the input tokens an AI agent needed to implement the same feature by 83 percent, at a measured upfront cost."
#AI#Coding Agents#Token Economics#Code Quality
Read Full Source

Ask Eljay

Ask about the studio's work, research, packages, or writing. A few starters:

Answers come from this site's own content and link their sources. For anything that matters, email hello@lightningjar.com.