代码寿命生存分析(CLSA):使用AST感知挖掘预测源代码行的存活
Code Lifespan Survival Analysis (CLSA): Predicting the Survival of Source Code Lines Using AST-Aware Mining
AI总结:
提出代码寿命生存分析(CLSA)框架,在单行粒度上通过Cox比例风险模型和AST结构、行熵等静态特征预测代码删除风险,发现行熵对成熟代码有强保护作用,仓库身份是最大影响因素。
摘要:
背景:预测哪些源代码行将被删除以及何时删除对于维护、技术债务和审查优先级很重要。现有的MSR方法在文件或方法粒度上工作,掩盖了单个语句的风险。目标:我们引入代码寿命生存分析(CLSA),这是第一个在单行粒度上建模代码生存的框架。CLSA将每一行视为一个右删失对象,并从结构、上下文和时间协变量中估计删除风险;其最强的预测因子可以静态地从单个文件(AST结构加行熵)计算,无需版本历史或错误数据。方法:我们从120个开源TypeScript仓库中挖掘了3250万个行出生事件。一个5阶段二分匹配流程将真正的删除与重构噪声(迁移和重写)分开,防止了830万个假死亡。我们拟合了一个包含15个协变量的Cox比例风险模型,并通过Weibull/Log-Logistic AFT、gamma脆弱性和时间分层界标模型检查稳健性。结果:超过一半的行从未被删除(Kaplan-Meier中位数未达到);在被删除的行中,中位寿命为95.7天。协变量效应强烈地随时间变化,形成三个区间。行香农熵对新代码有中等保护作用(HR=0.84,0-90天),对成熟代码有强保护作用(HR=0.36,365+天),这解释了其比例风险违反。条件分支中的行则相反:出生时保护(HR=0.97),90天后成为风险因素(HR=1.21)。仓库身份是最大的因素:一个gamma脆弱性模型(方差theta=1.449)将一致性从0.586提高到0.666,超过了每个结构协变量。结论:行级生存建模是可行的,产生可解释的、主要是静态的风险信号,以及用于IDE和代码审查中时间条件风险评分的校准方法。
英文摘要:
Superseded by arXiv:2611.10530. Context: Predicting which source lines will be deleted - and when - matters for maintenance and review prioritization. Existing MSR approaches work at file or method granularity, masking individual-statement risk. Objective: We introduce Code Lifespan Survival Analysis (CLSA), the first framework to model individual-line deletion risk from covariates - where prior line-granularity work estimated lifespans but found no significant predictors. CLSA treats each line as a right-censored subject and estimates deletion risk from structural, contextual, and temporal covariates; its strongest predictors are computable statically from one file (AST structure plus line token count), without version history or bug data. Method: We mine 32.5 million line birth events from 120 open-source TypeScript repositories. A 5-stage matching pipeline separates true deletions from refactoring noise, preventing 8.3 million false deaths. We fit a Cox Proportional Hazards model with 15 covariates and check robustness via Weibull/Log-Logistic AFT, gamma frailty, and time-stratified landmark models. Results: The Kaplan-Meier median survival time is 1,335-1,352 days (about 3.7 years), verified on the full 32.5-million-line population and an independent resample; among deleted lines the median lifespan is 95.7 days. Line token count is a steady protective factor (HR=0.87) that stays essentially flat with age (HR 0.89-0.91 across regimes). Lines in conditional branches show no detectable effect at birth (HR=0.98, 0-90 days, not significant) but become a risk factor after 90 days (HR=1.23). Repository identity is the largest factor: a gamma frailty model (variance theta=1.451) raises concordance from 0.587 to 0.676. Conclusion: Line-level survival modeling is tractable, yielding interpretable risk signals and a calibration recipe for time-conditional scoring in IDEs and code review.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。