Can Vision-Language Models Handle Long-Context Code? An Empirical Study on Visual Compression

Jianping Zhong, Guochang Li, Chen Zhi, Junxiao Han, Zhen Qin, Xinkui Zhao, Nan Wang, Shuiguang Deng, Jianwei YinarXiv 2026

TL;DR

The paper introduces LongCodeOCR, a novel visual compression framework that renders long-context source code into 2D image sequences for Vision-Language Models (VLMs). By treating code visually rather than textually, it preserves global structural dependencies and slashes preprocessing latency at 1M tokens from over 4 hours to just 1 minute.

What Problem Does This Paper Address?

As software engineering tasks scale from single files to entire repositories, Large Language Models (LLMs) must process massive contexts containing cross-file API definitions, configurations, and complex call graphs. However, standard LLMs hit a wall due to quadratic attention costs and hard context window limits.

Existing text-based compression methods (like LongCodeZip) try to fix this by selectively filtering out "unimportant" code chunks. Unfortunately, this binary keep-or-discard approach frequently breaks dependency closure—for instance, keeping a function call but deleting the definition or constructor it relies on. This causes semantic fragmentation and reasoning failures. Furthermore, calculating which text chunks to keep requires heavy LLM preprocessing overhead, making it computationally expensive and slow.

Fig. 1. A motivating example from RepoBench-P illustrating how selective filtering can break dependency closure. The SingleCellSelection definition (left, highlighted) is required for correct code completion but is removed after filtering (right, indicated by the masked region), causing irreversible coverage loss and an incorrect completion.

Methods

To avoid fragmenting code structure, the authors propose shifting from 1D textual filtering to 2D visual compression with LongCodeOCR.

Instead of pruning tokens, the framework renders the entire code context into a compact sequence of two-dimensional images. These images are then processed by a VLM's vision encoder into a fixed budget of visual tokens, preserving layout cues like indentation, alignment, and block structures.

Fig. 2. Framework overview of LongCodeOCR and two paradigms for long-context code compression. Stages 1– 3 depict how massive code contexts are rendered into a 2D image sequences and encoded into visual tokens for instruction-conditioned, cross-modal reasoning. The bottom panel highlights the contrast between the global-preserving visual view and the fragmented textual view.

The pipeline consists of three stages:

  1. Context Bottleneck: Identifying massive repository contexts that exceed standard text windows.
  2. Visual Rendering: Densifying the code into 2D image sequences without making irreversible keep-or-discard decisions.
  3. Cross-Modal Reasoning: Feeding the visual tokens alongside a textual instruction into a multimodal LLM backbone to perform downstream software engineering tasks.

Datasets

The authors evaluated LongCodeOCR across four long-context benchmarks targeting different aspects of code understanding:

  • Long Module Summarization: Project-level documentation generation requiring broad semantic abstraction.
  • LongCodeQA: A multiple-choice question-answering benchmark focused on cross-file reasoning.
  • Long Code Completion (LCC): A file-level completion task testing local semantic consistency and long-range constraints.
  • RepoBench-P: A repository-level code completion task using the Cross-File-First (XF-F) setting, where within-file context alone is insufficient.

Key Insights and Ideas

  • The Coverage–Fidelity Trade-off: Visual code compression operates on a fundamentally different axis than textual compression. Textual compression preserves symbol-level precision but sacrifices structural coverage (risking data loss). Visual compression preserves broad structural coverage but faces a fidelity bottleneck due to image resolution.
  • The "Visual Crowding" Effect: As context density scales up to extreme lengths, the rendered text (glyphs) becomes smaller and more crowded. This amplifies symbol-level noise, which doesn't hurt high-level semantic tasks (like summarization) but creates a bottleneck for exact character matching.
  • Shifting Compute Pressure: Textual compression methods hide their computational cost in the preprocessing stage by running numerous forward passes to score text chunks. Visual compression completely bypasses LLM-based scoring by utilizing lightweight graphical rendering.

Key Results

  • Superior Global Summarization: At a ~1.7× compression ratio, LongCodeOCR (using Qwen3-VL-8B) achieved a CompScore of 87.25, outperforming the state-of-the-art textual compressor LongCodeZip (50.40) by 36.85 points.
  • Massive Speedups: For a 1M-token context, LongCodeZip required roughly 4.3 hours of preprocessing latency and consumed 221M tokens just to compress the prompt. LongCodeOCR completed the visual compression in 70.36 seconds using 0 LLM tokens.
Table 1. Compression overhead of selective filtering-based compression. We report compression-stage latency and LLM token usage across input lengths. Lower values indicate lower overhead, the best (lowest) values are bolded.
  • Extreme Scaling Crossover: In ultra-long context regimes (1M tokens) on LongCodeQA, Glyph (a specialized 9B VLM using LongCodeOCR) maintained 70.00% accuracy at an extreme 12.2× compression ratio, outperforming LongCodeZip's 64.00% accuracy at a much lower 3.0× compression.

Limitations and Future Work

While visual compression excels at macro-level reasoning and global structure retention, it struggles with micro-level tasks requiring strict symbolic precision (like exact-match code completion) due to OCR noise.

To mitigate this, the authors suggest several future directions:

  1. Resolution-adaptive rendering and symbol-aware layouts to make characters clearer.
  2. Incorporating lightweight verification or correction mechanisms to clean up OCR noise before final generation.
  3. Developing hybrid pipelines that combine visual layouts with selective text filtering to get the best of both worlds.

Summary updated

BibTeX
@misc{zhong2026can,
  author = {Jianping Zhong and Guochang Li and Chen Zhi and Junxiao Han and Zhen Qin and Xinkui Zhao and Nan Wang and Shuiguang Deng and Jianwei Yin},
  title = {{Can Vision-Language Models Handle Long-Context Code? An Empirical Study on Visual Compression}},
  year = {2026},
  eprint = {2602.00746},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.00746},
}
Figure