LLM-based Source Code Compression via Thresholded Symbol Ranking
作者: Angelo Nardone, Paolo Ferragina
分类: cs.IT, cs.CL, cs.LG
发布日期: 2026-07-27
💡 一句话要点
提出基于LLM的源代码压缩方法以解决存储需求问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 源代码压缩 无损压缩 大规模软件存储 符号排名 大语言模型 压缩算法 信息理论
📋 核心要点
- 现有的通用压缩算法未能充分利用源代码的特殊规律,导致压缩效果不理想。
- 本文提出了一种基于LLM的压缩方法,采用前$T$个排名限制,提升了压缩效率。
- 实验结果显示,所提方法在压缩比上相较于现有LLM压缩方法提升了37%,速度提升40%。
📝 摘要(中文)
本文研究了源代码的无损压缩问题,旨在应对大型软件档案(如Software Heritage)的存储需求。现有的通用压缩算法(如zstd、bzip2)在压缩比和速度之间提供了良好的权衡,但未能充分利用源代码固有的特殊规律。我们提出了一种新的LLM压缩方法,采用两种符号排名变体,将预测限制在前$T$个排名内,并将超出阈值的符号作为例外进行存储。通过对30种LLM的评估,我们的方法在压缩比和速度上均优于现有的LLM压缩方法,显示出源代码的规律性更易被捕捉。
🔬 方法详解
问题定义:本文旨在解决源代码的无损压缩问题,现有的通用压缩算法(如zstd、bzip2)未能有效利用源代码的特殊规律,导致压缩效果不佳,且在速度上存在瓶颈。
核心思路:我们提出了一种基于LLM的压缩方法,通过限制符号排名在前$T$个($T=1$或$63$),将超出阈值的符号作为例外进行存储,并与排名流一起通过通用压缩算法进行压缩,这样设计旨在提高压缩效率并降低吞吐量损失。
技术框架:整体架构包括两个主要模块:符号排名模块和通用压缩模块。符号排名模块利用LLM对源代码进行分析并生成排名,通用压缩模块则负责对超出排名的符号进行压缩处理。
关键创新:本文的主要创新在于引入了$T$-bounded符号排名方法,显著提升了压缩比和速度,尤其是在源代码压缩中表现优异,与现有方法相比,能够更好地捕捉源代码的规律性。
关键设计:在参数设置上,$T$的选择(1或63)对压缩效果有显著影响,此外,采用的损失函数和网络结构经过优化,以确保在压缩过程中保持信息的完整性和准确性。
🖼️ 关键图片
📊 实验亮点
实验结果表明,所提$T$-bounded方法在压缩比上相较于现有LLM压缩方法提升了37%,在压缩速度上提升了40%。与通用压缩算法相比,获得了高达82%的相对压缩增益,尽管速度略低,提供了压缩与速度之间的新权衡点。
🎯 应用场景
该研究的潜在应用领域包括大型软件存储、版本控制系统以及云计算环境中的源代码管理。通过有效的源代码压缩,可以显著降低存储成本,提高数据传输效率,具有重要的实际价值和广泛的应用前景。
📄 摘要(原文)
We study the problem of lossless compression of source code, motivated by the storage demands of large-scale software archives, such as Software Heritage (https://www.softwareheritage.org/). General-purpose compressors (e.g., zstd, bzip2) offer a good trade-off between compression ratio and speed, but fail to exploit all special regularities inherent in source code. Recent approaches leverage Large Language Models (LLMs) within Shannon's symbol-ranking framework, relying on a scheme in which the predicted rank can grow arbitrarily. While effective at reducing space, this setting incurs significant throughput degradation, and leaves open the question whether it is necessary to explicitly encode all ranks. In this work, we introduce LLM-based compressors deploying two novel symbol-ranking variants that bound predictions to the top-$T$ ranks ($T=1$ or $63$), with out-of-threshold symbols stored as exceptions and compressed jointly with the rank stream via general-purpose compressors. We conduct the first large-scale evaluation of LLM-based source code compression across 30 LLMs, including general-domain, code-specialized, and quantized models. Our $T$-bounded approach outperforms prior LLM-based compressors both in compression ratio (up to 37% relative improvement) and compression throughput (40% faster). Compared to general-purpose compressors (e.g., zstd, bzip2), we obtain up to 82% relative compression gain but at a lower speed, thus offering a new trade-off point in the compression-speed spectrum. We also show that these gains are stronger on source code than on natural language, suggesting an interesting indication, namely that source code exposes regularities captured by LLMs but missed by general-purpose exact-match-based compressors. We conclude by commenting on open problems that offer theoretical and practical avenues of research.