LongCodeZip: Comprimeer Lange Context voor Code Taalmodellen
LongCodeZip: Compress Long Context for Code Language Models
October 1, 2025
Auteurs: Yuling Shi, Yichun Qian, Hongyu Zhang, Beijun Shen, Xiaodong Gu
cs.AI
Samenvatting
Codegeneratie in lange contexten wordt steeds kritischer naarmate
Large Language Models (LLMs) moeten redeneren over uitgebreide informatie
in de codebase. Hoewel recente vooruitgang code-LLMs in staat stelt om lange invoeren te verwerken,
blijven hoge API-kosten en generatielatentie aanzienlijke knelpunten. Bestaande
technieken voor contextreductie, zoals LLMLingua, behalen veelbelovende resultaten voor
algemene tekst, maar negeren code-specifieke structuren en afhankelijkheden, wat leidt tot
suboptimale prestaties bij programmeertaken. In dit artikel stellen we
LongCodeZip voor, een innovatief plug-and-play codecompressieframework dat specifiek is ontworpen
voor code-LLMs. LongCodeZip maakt gebruik van een tweefasenstrategie: (1)
grove compressie, waarbij functieniveau-chunks worden geïdentificeerd en gerangschikt
op basis van conditionele perplexiteit ten opzichte van de instructie, waarbij alleen
de meest relevante functies worden behouden; en (2) fijne compressie, waarbij
behouden functies worden gesegmenteerd in blokken op basis van perplexiteit en een optimale
subset wordt geselecteerd binnen een adaptief tokenbudget om de relevantie te maximaliseren. Evaluaties over
meerdere taken, waaronder codecompletering, samenvatting en vraagbeantwoording,
laten zien dat LongCodeZip consistent beter presteert dan baseline-methoden,
met een compressieverhouding van tot wel 5,6x zonder de taakprestaties te verslechteren. Door
effectief de contextgrootte te verkleinen terwijl essentiële informatie behouden blijft,
maakt LongCodeZip het mogelijk dat LLMs beter kunnen schalen naar realistische, grootschalige code-
scenario's, wat de efficiëntie en capaciteit van code-intelligentieapplicaties bevordert.
English
Code generation under long contexts is becoming increasingly critical as
Large Language Models (LLMs) are required to reason over extensive information
in the codebase. While recent advances enable code LLMs to process long inputs,
high API costs and generation latency remain substantial bottlenecks. Existing
context pruning techniques, such as LLMLingua, achieve promising results for
general text but overlook code-specific structures and dependencies, leading to
suboptimal performance in programming tasks. In this paper, we propose
LongCodeZip, a novel plug-and-play code compression framework designed
specifically for code LLMs. LongCodeZip employs a dual-stage strategy: (1)
coarse-grained compression, which identifies and ranks function-level chunks
using conditional perplexity with respect to the instruction, retaining only
the most relevant functions; and (2) fine-grained compression, which segments
retained functions into blocks based on perplexity and selects an optimal
subset under an adaptive token budget to maximize relevance. Evaluations across
multiple tasks, including code completion, summarization, and question
answering, show that LongCodeZip consistently outperforms baseline methods,
achieving up to a 5.6x compression ratio without degrading task performance. By
effectively reducing context size while preserving essential information,
LongCodeZip enables LLMs to better scale to real-world, large-scale code
scenarios, advancing the efficiency and capability of code intelligence
applications.