用程序结构信息压缩代码生成的缓存,提升长代码处理效率。
CodeComp: Structural KV Cache Compression for Agentic Coding

- 结合静态分析提取代码结构先验,指导缓存压缩。
- 在有限内存下恢复大部分完整上下文准确率。
- 适合需要处理长代码的智能编程系统使用。
智能代码任务如错误定位和补丁生成需在内存受限条件下处理长代码库,此时键值(KV)缓存成为主要推理瓶颈。现有压缩方法仅依赖注意力信号评估令牌重要性,系统性丢弃调用点、分支条件、赋值等对代码理解至关重要的结构性关键令牌。我们提出 CodeComp,一种无需训练的 KV 缓存压缩框架,通过 Joern 提取的代码属性图先验将静态程序分析融入大模型推理。在错误定位与代码生成基准上,CodeComp 在相同内存预算下持续优于仅依赖注意力的压缩基线,实现高压缩率下的多数完整上下文准确率恢复,且补丁生成质量与未压缩全上下文推理相当,并可无缝集成至 SGLang 基于的智能编码流水线,无需修改模型。
原文摘要 · Abstract (English)
Agentic code tasks such as fault localization and patch generation require processing long codebases under tight memory constraints, where the Key-Value (KV) cache becomes the primary inference bottleneck. Existing compression methods rely exclusively on attention signals to estimate token importance, systematically discarding structurally critical tokens such as call sites, branch conditions, and assignments that are essential for code understanding. We present CodeComp, a training-free KV cache compression framework that incorporates static program analysis into LLM inference via Code Property Graph priors extracted by Joern. Across bug localization and code generation benchmarks, CodeComp consistently outperforms attention-only compression baselines under equal memory budgets, recovering the majority of full-context accuracy under aggressive KV cache compression, while matching the patch generation quality of uncompressed full-context inference and integrating seamlessly into SGLang-based agentic coding pipelines without model modification.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。