An Empirical Study on the Code Refactoring Capability of Large Language Models
Large Language Models (LLMs) aim to generate and understand human-like text by leveraging deep learning and natural language processing techniques. In software development, LLMs can enhance the coding experience through coding automation, reducing development time and improving code quality. Code refactoring is a technique used to enhance the internal quality of the code base without altering its external functionalities. Leveraging LLMs for code refactoring can help developers improve code quality with minimal effort. This article presents an empirical study evaluating the quality of refactored code produced by StarCoder2, GPT-4o Mini, GPT-4o, LLaMA 3, and DeepSeek-v3. Specifically, we (1) evaluate whether the code refactored by the LLMs can improve code quality, (2) understand the differences between the types of refactoring applied by the different LLMs and compare their effectiveness, and (3) evaluate whether the quality of the refactored code generated by the LLM can be improved through one-shot prompting and chain-of-thought prompting. We analyze the refactoring capabilities of LLMs on 30 open source Java projects. We evaluate StarCoder2, LLaMA 3, GPT-4o Mini, GPT-4o, and DeepSeek-v3 on their ability to improve static code quality metrics, pass unit tests, and reduce code smells. Our findings reveal that production-grade models such as GPT-4o and DeepSeek-v3 achieve pass@5 unit test success rates above 90% on multi-file refactorings. LLaMA 3 achieves the highest overall code smell reduction with a median reduction of 15.1%, while DeepSeek-v3 and GPT-4o achieve the greatest improvements in cohesion, coupling, and complexity. StarCoder2 demonstrates strengths in modularity improvements and systematic refactorings. Developers outperform LLMs in complex, context-sensitive refactorings such as attribute encapsulation.
- Link
- https://doi.org/10.1145/3801158
- Found by
- Crossref
- Authors
- Jonathan Cordeiro, Shayan Noei, Ying Zou
- Organizations
- Electrical and Computer Engineering, Queen’s University, Kingston, Ontario, Canada, Queen's University
- Categories
- evaluation
- Published
- 2026-11-18
- Last seen by the radar
- 2026-11-20
- Citations
- 94
- Radar score
- 43.23 / 100 (how it is scored)
- Why it scored so
- Also found via OpenAlex; Matched: evaluat; Primary record: Crossref