A Taxonomy of Inefficiencies in LLM-Generated Python Code

TL;DR

This study proposes a taxonomy of 19 inefficiency patterns in 492 LLM-generated Python codes, validated through expert surveys.

cs.SE 🔴 Advanced 2025-03-09 54 views
Altaf Allah Abbassi Leuson Da Silva Amin Nikanjam Foutse Khomh
AI Code Generation Software Quality Large Language Models Efficiency

Key Findings

Methodology

Using HumanEval+ benchmark, 492 Python snippets were generated by CodeLlama, DeepSeek-Coder, and CodeGemma. GPT-4o-mini served as an automated judge to identify efficiency issues. Manual analysis with open coding extracted five main categories and 19 subcategories of inefficiencies. Validation involved a survey with 58 practitioners and researchers, confirming the taxonomy's relevance and completeness.

Key Results

  • Analysis revealed that logic errors (35%) and performance bottlenecks (28%) are the most prevalent inefficiencies, often co-occurring with readability and maintainability issues, significantly impacting overall code quality.
  • Multiple inefficiencies co-exist in 33.54% of samples, indicating complex interrelations. The survey confirmed the taxonomy's practical relevance, with experts emphasizing the importance of addressing logic and performance issues.
  • Model-generated code frequently exhibits redundant steps, memory inefficiencies, and slow execution, providing clear targets for future optimization efforts.

Significance

This research addresses the gap in systematic understanding of efficiency issues in LLM-generated code, offering a structured framework for evaluation. It has implications for improving model training, automated detection, and refactoring tools, thus accelerating adoption of AI-assisted coding in industry and academia.

Technical Contribution

The paper introduces a comprehensive taxonomy covering five categories and 19 subcategories, validated through empirical analysis and expert feedback. It innovatively combines automated judgment with manual coding, establishing a foundation for automated efficiency detection and targeted model improvements.

Novelty

First to systematically classify efficiency problems in LLM-generated Python code across multiple dimensions, surpassing prior bug-focused studies. The multi-method validation enhances robustness, providing a new perspective on code quality beyond correctness.

Limitations

  • Sample limited to open-source models and specific datasets, which may not fully represent commercial or diverse task scenarios.
  • Judgment relies on GPT-4o-mini, which may introduce bias or miss subtle issues.
  • Survey participants are industry experts, possibly skewing results; broader validation is needed.

Future Work

Future directions include developing automated tools for detecting and fixing identified inefficiencies, extending the taxonomy to other languages and tasks, and integrating efficiency metrics into model training objectives for end-to-end optimization.

AI Executive Summary

Large Language Models (LLMs) have revolutionized automated code generation, but their outputs often suffer from efficiency issues that hinder practical deployment. While prior research has focused on correctness and security, a systematic understanding of inefficiencies remains lacking. This study analyzes 492 Python snippets generated by leading open-source models—CodeLlama, DeepSeek-Coder, and CodeGemma—using a hybrid approach of automated judgment via GPT-4o-mini and manual coding. The goal was to identify, categorize, and validate inefficiency patterns affecting code quality.

The researchers developed a taxonomy comprising five main categories: General Logic, Performance, Readability, Maintainability, and Errors, with 19 subcategories. For example, logic issues include wrong or partially wrong logic, while performance issues cover sub-optimal algorithms and unnecessary steps. The validation through a survey of 58 practitioners confirmed the relevance and prevalence of these patterns, especially logic and performance inefficiencies, which frequently co-occur and significantly impact overall quality.

This classification provides a structured foundation for automated detection and targeted optimization of LLM-generated code. It highlights key areas where models can be improved, such as reducing redundant steps and enhancing logical coherence. The findings underscore the importance of addressing efficiency alongside correctness to foster broader industrial adoption. Future work aims to develop automated tools for real-time efficiency assessment and extend the taxonomy across languages and tasks, ultimately guiding the evolution of more effective AI-driven coding systems.

Deep Analysis

Background

Recent advances in LLMs like GPT-4, Codex, and Llama have significantly improved automated code generation, enabling rapid prototyping and assisting developers. Prior work primarily focused on correctness, security, and bug detection, with models like DeepMind's AlphaCode and OpenAI's Codex showing notable success. However, as models scale, inefficiencies such as redundant computations, poor algorithm choices, and maintenance challenges become prominent. Existing studies lack a systematic taxonomy to categorize these issues comprehensively, limiting targeted improvements. The gap between high-level performance and practical efficiency necessitates detailed analysis to guide future model training and tooling.

Core Problem

Despite high functional accuracy, LLM-generated code often suffers from inefficiencies that degrade runtime performance, increase resource consumption, and complicate maintenance. These issues include poorly optimized algorithms, excessive redundancy, and unclear code structure, which collectively hinder real-world deployment. The absence of a unified framework to identify and address these inefficiencies hampers progress. Practitioners face difficulty in diagnosing and fixing these problems, leading to manual, time-consuming efforts. Addressing this gap requires a systematic, empirical approach to classify and validate efficiency issues, providing actionable insights for model developers and users.

Innovation

This work introduces a comprehensive taxonomy of inefficiency patterns in LLM-generated Python code, covering five main categories and 19 subcategories. Unlike prior bug-focused studies, it emphasizes efficiency aspects like performance bottlenecks, code readability, and maintainability. The methodology combines automated judgment from GPT-4o-mini with manual open coding, ensuring robustness and depth. Validation through expert surveys confirms the taxonomy's practical relevance. The approach bridges the gap between theoretical model capabilities and real-world deployment needs, offering a structured framework for future research and tooling development.

Methodology

  • �� Generate code snippets from HumanEval+ using CodeLlama, DeepSeek-Coder, and CodeGemma with fixed prompts and temperature=0 for determinism.
  • �� Use GPT-4o-mini as an automated judge, inputting code and task descriptions to identify inefficiencies.
  • �� Manually analyze a pilot set (196 samples) with open coding, iteratively defining categories and subcategories.
  • �� Expand to full dataset (492 samples), with two raters independently labeling, resolving discrepancies via discussion.
  • �� Validate taxonomy through a survey with 58 practitioners, collecting feedback on relevance and prevalence.
  • �� Refine categories based on feedback, achieving high inter-rater agreement (Cohen’s Kappa > 0.7).

Experiments

The experimental setup involves generating code for 164 tasks across three models, with fixed prompts to ensure comparability. GPT-4o-mini evaluates each snippet for inefficiency patterns, supplemented by manual analysis to refine categories. The survey assesses practitioners’ perceptions of these inefficiencies, measuring frequency and importance via Likert scales. Data analysis includes frequency distribution, co-occurrence patterns, and correlation with model types. The robustness is tested through inter-rater agreement and cross-model comparisons, providing comprehensive insights into prevalent inefficiency patterns.

Results

Analysis shows that logic errors (35%) and performance issues (28%) are most common, often co-occurring with readability and maintainability problems. Multiple inefficiencies appear in over one-third of samples, indicating complex interactions. Experts validated the taxonomy's comprehensiveness and relevance, confirming that these inefficiencies reflect real-world challenges. The study highlights specific issues like unnecessary steps, sub-optimal algorithms, and poor variable naming, which can be targeted for future model improvements. The results guide both model developers and tool creators towards more efficient code generation.

Applications

The taxonomy can be integrated into automated code review tools, enabling real-time detection of inefficiencies. It also informs training objectives for future models to prioritize efficiency alongside correctness. Industry practitioners can use it to diagnose and improve LLM outputs, reducing manual effort. Long-term, the framework supports developing self-healing systems that automatically optimize generated code, accelerating the adoption of AI-assisted software engineering and reducing resource costs.

Limitations & Outlook

The study relies on open-source models and specific datasets, which may not fully capture commercial or domain-specific scenarios. The judgment model (GPT-4o-mini) might introduce biases or miss subtle issues. The survey sample, though expert, is limited in scope, possibly affecting generalizability. Future work should include broader datasets, diverse model architectures, and automated detection tools to enhance robustness and applicability across different contexts.

Plain Language Accessible to non-experts

想象你在厨房做饭,厨师(模型)需要用不同的材料(代码)做出一道菜(程序)。如果厨师只会随便放材料,没有考虑味道或做法,就会做出不合口味的菜(逻辑错误)。有时候,厨师会用多余的调料或重复步骤,导致菜变得繁琐(冗余、低效)。有些菜看起来虽然好吃,但做得太复杂,难以复制(难以维护)。这些问题就像模型生成的代码,虽然可以完成任务,但常常存在逻辑不清、效率低、难维护的问题。我们通过分析很多菜谱(代码),总结出常见的“缺陷类型”,帮助厨师(模型)做得更好,做出既快又好吃的菜(高效优质的程序)!

ELI14 Explained like you're 14

想象你在学校的厨房里做饭,厨师(模型)要用不同的材料(代码元素)做出一道菜(程序)。有时候,厨师会用错材料,比如用糖代替盐,结果菜变得奇怪(逻辑错误)。有时候,厨师会用太多重复的调料,浪费时间和材料(冗余)。还会用太复杂的方法做菜,学起来很难,也不方便别人学会(维护困难)。我们发现,这些问题在模型做的代码里很常见。通过分析很多模型做的菜(代码),我们总结出常见的缺陷,比如“逻辑不对”、“太慢”、“太复杂”。这样,厨师(模型)以后就能避免这些问题,做出更快、更好吃的菜(高效、易维护的程序)!

Abstract

Large Language Models (LLMs) are widely adopted for automated code generation with promising results. Although prior research has assessed LLM-generated code and identified various quality issues -- such as redundancy, poor maintainability, and sub-optimal performance a systematic understanding and categorization of these inefficiencies remain unexplored. Without such knowledge, practitioners struggle to optimize LLM-generated code for real-world applications, limiting its adoption. This study can also guide improving code LLMs, enhancing the quality and efficiency of code generation. Therefore, in this study, we empirically investigate inefficiencies in LLM-generated code by state-of-the-art models, i.e., CodeLlama, DeepSeek-Coder, and CodeGemma. To do so, we analyze 492 generated code snippets in the HumanEval++ dataset. We then construct a taxonomy of inefficiencies in LLM-generated code that includes 5 categories General Logic, Performance, Readability, Maintainability, and Errors) and 19 subcategories of inefficiencies. We then validate the proposed taxonomy through an online survey with 58 LLM practitioners and researchers. Our study indicates that logic and performance-related inefficiencies are the most popular, relevant, and frequently co-occur and impact overall code quality inefficiency. Our taxonomy provides a structured basis for evaluating the quality LLM-generated code and guiding future research to improve code generation efficiency.

cs.SE