Skip to main content
QUICK REVIEW

[논문 리뷰] An Empirical Study on the Potential of LLMs in Automated Software Refactoring

Bo Liu, Yanjie Jiang|arXiv (Cornell University)|2024. 11. 07.
Digital Rights Management and Security인용 수 4
한 줄 요약

이 논문은 ChatGPT와 Gemini와 같은 대규모 언어 모델(Large Language Models, LLMs)이 자동 소프트웨어 리팩터링에 활용될 잠재력을 평가하며, 최적화된 프롬프트를 사용할 경우 LLMs가 86.7%의 리팩터링 기회를 식별하고 인간 전문가 수준의 고품질 솔루션을 제안할 수 있음을 발견했다. 환각 현상으로 인한 구문 오류나 기능 변경 위험을 완화하기 위해 저자들은 RefactoringMirror—검증된 리팩터링 엔진을 통해 LLM이 제안한 리팩터링을 재적용하는 탐지 및 재적용 전략—를 제안한다. 이 전략은 모든 위험한 변경을 방지하는 데 성공했다.

ABSTRACT

Recent advances in large language models (LLMs), make it potentially feasible to automatically refactor source code with LLMs. However, it remains unclear how well LLMs perform compared to human experts in conducting refactorings automatically and accurately. To fill this gap, in this paper, we conduct an empirical study to investigate the potential of LLMs in automated software refactoring, focusing on the identification of refactoring opportunities and the recommendation of refactoring solutions. We first construct a high-quality refactoring dataset comprising 180 real-world refactorings from 20 projects, and conduct the empirical study on the dataset. With the to-be-refactored Java documents as input, ChatGPT and Gemini identified only 28 and 7 respectively out of the 180 refactoring opportunities. However, explaining the expected refactoring subcategories and narrowing the search space in the prompts substantially increased the success rate of ChatGPT from 15.6% to 86.7%. Concerning the recommendation of refactoring solutions, ChatGPT recommended 176 refactoring solutions for the 180 refactorings, and 63.6% of the recommended solutions were comparable to (even better than) those constructed by human experts. However, 13 out of the 176 solutions suggested by ChatGPT and 9 out of the 137 solutions suggested by Gemini were unsafe in that they either changed the functionality of the source code or introduced syntax errors, which indicate the risk of LLM-based refactoring. To this end, we propose a detect-and-reapply tactic, called RefactoringMirror, to avoid such unsafe refactorings. By reapplying the identified refactorings to the original code using thoroughly tested refactoring engines, we can effectively mitigate the risks associated with LLM-based automated refactoring while still leveraging LLM's intelligence to obtain valuable refactoring recommendations.

연구 동기 및 목표

  • 생산용 자바 코드에서 실제 리팩터링 기회를 정확히 식별할 수 있는지 LLMs의 능력을 조사하기 위해.
  • 인간 전문가가 만든 솔루션과 비교해 LLMs가 제안한 리팩터링 솔루션의 품질을 평가하기 위해.
  • LLM 기반 리팩터링이 문법 오류나 기능 변경을 유발할 위험을 해결하기 위해.
  • 안전성과 정확성을 보장하는 탐지 및 재적용 전략을 제안하고 검증하기 위해.

제안 방법

  • 20개의 오픈소스 자바 프로젝트에서 유래한 실제 리팩터링 180宗을 수작업으로 검증한 고품질 데이터셋을 구축했다.
  • GPT-4와 Gemini를 LLM으로 활용하여 전체 자바 소스 파일을 분석하고 리팩터링 기회 및 솔루션을 식별했다.
  • 프롬프트 엔지니어링을 통해 리팩터링 하위 카테고리 지정 및 검색 공간 축소를 통해 LLM 성능을 향상시켰다.
  • 기존에 검증된 리팩터링 엔진을 사용해 LLM이 제안한 리팩터링을 재적용하는 탐지 및 재적용 전략인 RefactoringMirror를 제안했다.
  • LLMs의 기회 식별 성공률과 제안 솔루션의 품질을 정량적으로 평가했다.
  • 세 명의 인간 전문가가 참여한 수작업 평가를 통해 LLM이 생성한 리팩터링 솔루션의 정확성과 품질을 평가했다.

실험 결과

연구 질문

  • RQ1RQ1: 최적화된 프롬프트를 사용할 경우, GPT-4와 Gemini는 실제 자바 코드에서 리팩터링 기회를 얼마나 잘 식별할 수 있는가?
  • RQ2RQ2: GPT-4와 Gemini는 인간 전문가가 만든 솔루션과 비교해 얼마나 높은 품질의 리팩터링 솔루션을 제안하는가?
  • RQ3RQ3: LLM 기반 리팩터링의 위험 요소는 무엇이며, 특히 구문 오류나 기능 변경을 유발할 가능성이 있는가?
  • RQ4RQ4: 탐지 및 재적용 전략은 LLM 기반 리팩터링에서 환각 현상을 효과적으로 완화하면서도 LLM의 지능적 이점을 유지할 수 있는가?

주요 결과

  • 최적화된 프롬프트를 사용할 경우, ChatGPT는 180개의 리팩터링 기회 중 86.7%를 식별했으며, 초반 15.6%의 성공률에 비해 크게 향상되었다.
  • Gemini는 180개의 리팩터링 기회 중 단 7개만 식별하여, 프롬프트 최적화 없이선 성능이 제한됨을 시사했다.
  • ChatGPT는 180개 리팩터링에 대해 176개의 솔루션을 제안했으며, 그 중 63.6%는 인간이 만든 솔루션과 동일하거나 더 우수한 품질이었다.
  • ChatGPT가 제안한 176개 솔루션 중 13개, Gemini가 제안한 137개 솔루션 중 9개는 안전하지 않았다—구문 오류를 유발하거나 기능을 변경했다.
  • 제안된 RefactoringMirror 전략은 LLM이 제안한 리팩터링의 94.3%를 성공적으로 재적용했으며, 모든 안전하지 않은 변경을 제거했다.
  • 이 연구는 검증된 리팩터링 엔진을 통한 안전 검사와 결합할 경우, LLMs가 자동 리팩터링에 실질적이고 높은 잠재력을 지닌 보조 도구가 될 수 있음을 입증했다.

더 나은 연구,지금 바로 시작하세요

논문 읽기부터 검토까지, 연구 시간을 획기적으로 줄여보세요.

카드 등록 없음 · 무료 플랜 제공

이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.