Chapter 3. AI-Generated Code and the Performance Paradox
AI-assisted code generation has rapidly moved from a novelty to an everyday tool in modern development. Large language models (LLMs) and AI coding assistants can produce web application code in seconds, offering solutions that appear to work in the browser. This speed and convenience, however, come with a paradox: These tools currently optimize for correctness (satisfying the prompt’s intent) and perhaps style—not for performance. The training data they learn from is a mix of code from the web, which includes both good and bad practices. So an AI might regurgitate a solution that works but isn’t optimal, efficient, accessible, or user-friendly. In practice, many developers are discovering that AI-generated apps function adequately but exhibit serious performance and quality issues when held to real-world standards.
This chapter looks at the problem at a high level and evaluates how human developers’ role is evolving. The chapters that follow will then offer some concrete techniques for optimizing AI-generated code.
AI Outputs: Correct but Not Optimal
LLMs have essentially ingested the world’s open source code and learned common patterns. This means the code they generate tends to follow the average practices found online. Unfortunately, “average” web code is often far from ideal in terms of performance. For instance, many web tutorials use simplistic approaches for clarity (like using for…in loops in ways that aren’t optimal, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access