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)|Nov 7, 2024
Digital Rights Management and Security被引用数 4
ひとこと要約

この論文は、ChatGPT や Gemini などの大規模言語モデル(LLM)が自動ソフトウェアリファクタリングにどの程度有効であるかを評価し、最適化されたプロンプトを用いることで、LLM が 86.7% のリファクタリング機会を特定し、人間の専門家と同等の高品質な解決策を提案できることを明らかにした。幻覚現象による構文エラーや機能の変更を回避するため、著者らは、検証済みのリファクタリングエージェントを介して LLM が提案したリファクタリングを再適用する「RefactoringMirror」という検出・再適用戦略を提案した。この戦略により、すべての危険な変更が回避された。

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.

研究の動機と目的

  • LLM が実際の生産環境の Java コードにおいて、現実のリファクタリング機会を正確に特定できるかどうかを調査すること。
  • LLM が提案するリファクタリング解決策の質が、人間の専門家が作成した解決策と比べてどの程度であるかを評価すること。
  • LLM が生成するリファクタリングが、構文エラーや機能の変更を引き起こすリスクを特定すること。
  • 安全で正確な LLM ベースのリファクタリングを保証する検出・再適用戦略を提案し、実証すること。

提案手法

  • 20 個のオープンソース Java プロジェクトから、人間の専門家によって手動で検証済みの 180 件の実世界のリファクタリングを含む高品質なデータセットを構築した。
  • GPT-4 および Gemini を LLM として用い、Java ソースファイル全体を分析し、リファクタリングの機会と解決策を特定した。
  • プロンプト工学を用いた—具体的には、リファクタリングのサブカテゴリを明示し、探索空間を狭める—ことで、LLM のパフォーマンスを向上させた。
  • 検出・再適用戦略として、既存で検証済みのリファクタリングエージェントを用いて LLM が提案したリファクタリングを再適用する「RefactoringMirror」を提案した。
  • LLM がリファクタリング機会を特定する成功率と、提案された解決策の質を定量的に評価した。
  • 3 名の人的専門家による手動評価を通じて、LLM が生成したリファクタリング解決策の正しさと質を評価した。

実験結果

リサーチクエスチョン

  • RQ1RQ1: 最適化されたプロンプトを用いる場合、LLM(GPT-4 および Gemini)は実世界の Java コードにおけるリファクタリング機会をどの程度正確に特定できるか?
  • RQ2RQ2: GPT-4 および Gemini は、人間の専門家が作成した解決策と比べて、どの程度高品質なリファクタリング解決策を提案できるか?
  • RQ3RQ3: LLM ベースのリファクタリングにおけるリスク、特に機能的・構文的エラーを引き起こすリスクは何か?
  • RQ4RQ4: 検出・再適用戦略は、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% が再適用され、すべての危険な変更が排除された。
  • 本研究は、LLM が検証済みのリファクタリングエージェントを介した安全対策と組み合わせることで、自動リファクタリングにおける実用的で高いポential を持つ支援手段であることを示した。

より良い研究を、今すぐ始めましょう

論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。