arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2602.07882cs.SE
收藏

通过大语言模型的视角重新思考代码复杂度

Rethinking Code Complexity Through the Lens of Large Language Models

School of Computer Science, Shanghai Jiao Tong University(上海交通大学计算机学院)

Chen Xie, Xiaodong Gu, Yuling Shi, Beijun Shen

AI总结:

针对传统复杂度指标与LLM感知难度不匹配的问题,提出基于语义非线性的熵引导语义组合层次复杂度度量LM-CC,实验证明其与LLM性能强相关且语义保持的复杂度降低能提升下游任务表现。

摘要:

诸如圈复杂度之类的代码复杂度指标长期以来一直被用于评估软件质量和可维护性。随着大语言模型(LLM)在编码任务上的快速进步,一个重要但尚未充分探索的问题出现了:传统的复杂度指标是否有意义地刻画了LLM感知的编码难度?在这项工作中,我们通过实验证明,经典的复杂度指标与LLM性能之间没有一致的相关性,揭示了与模型感知难度之间的根本性不匹配。为了解决这一差距,我们提出了LM-CC,一种专为LLM定制的新型代码复杂度度量,其基础假设是模型感知的代码难度根本上由语义非线性驱动。LM-CC通过熵引导的语义组合层次来量化复杂度,捕捉LLM在代码理解过程中遇到的累积不确定性。我们的实验结果表明,LM-CC与LLM性能表现出强且一致的部分相关性,而LM-CC的语义保持降低则持续导致下游任务性能的提升。源代码可在 https://github.com/xchen121/lm-cc 获取。

英文摘要:

Code complexity metrics such as cyclomatic complexity have long been used to assess software quality and maintainability. With the rapid advancement of large language models (LLMs) on coding tasks, an important yet underexplored question arises: do traditional complexity metrics meaningfully characterize the coding difficulty that LLMs perceive? In this work, we empirically demonstrate that classical complexity metrics exhibit no consistent correlation with LLM performance, revealing a fundamental mismatch with model-perceived difficulty. To address this gap, we propose LM-CC, a novel code complexity metric tailored for LLMs, grounded in the hypothesis that model-perceived code difficulty is fundamentally driven by semantic nonlinearity. LM-CC quantifies complexity through an entropy-guided semantic compositional hierarchy, capturing the cumulative uncertainty encountered by LLMs during code understanding. Our experimental results demonstrate that LM-CC exhibits strong and consistent partial correlations with LLM performance, while semantics-preserving reductions in LM-CC consistently lead to improved downstream task performance. The source code is available at: https://github.com/xchen121/lm-cc.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑