CodeShrink: Adaptive Visual Compression for Efficient Multimodal Code Understanding
Wenxin Tang, Jingyu Xiao, Zhenyu Liu, Zipeng Xie, Junliang Liu, Wang Luo, Yuan Jiang, Yintong Huo, Michael Lyu
Abstract
Rendering source code as images offers a promising way to reduce the input costs of Multimodal Large Language Models (MLLMs). Adjusting image resolution can trade visual token cost against content fidelity. However, resolution scaling alone overlooks two sources of inefficiency: blank regions created by line breaks and indentation, and code regions irrelevant to the current instruction. Moreover, the best compression setting varies across inputs, tasks, and models, limiting fixed-ratio strategies. We propose CodeShrink, an adaptive visual compression framework with three components. Blank-Free Rendering replaces whitespace-dependent layouts with compact layouts and explicit structural markers, removing layout-induced tokens. Adaptive Compression Configuration uses a lightweight agent trained with reinforcement learning to predict a per-input setting that balances token efficiency and readability. Dominant Token Selection jointly analyzes the instruction and code image to prune task-irrelevant visual tokens during inference. We evaluate CodeShrink on code question answering, clone detection, and code completion. CodeShrink reduces visual token use by up to 71.2\% while matching or exceeding uncompressed text-only inputs, and consistently outperforms text-based and visual compression baselines across all three tasks. These results show that combining layout compaction, adaptive configuration, and instruction-aware pruning can make multimodal code understanding more efficient. Our code is available at https://github.com/vinsontang1/CodeShrink.
Create a lesson
Related papers
Parameter-Efficient CLIP Adaptation for 3D Understanding via Unified Tokenization
Shared title terminology · Guofeng Mei, Qinfeng Xiao, Bin Ren et al.
SAVIOR: Sample-efficient Adaptation of Vision-Language Models for OCR Representation
Shared title terminology · Akshata A Bhat, Sharath Naganna, Saiful Haq et al.
Can Reasoning and Image Description Enhance Yes/No Visual Mathematical Understanding?
Shared title terminology · Guangcheng Song, Weichuan Wang, Linqi Song
Parameter-Efficient Adaptation of Qwen3-VL for Handwritten Mathematical Expression Recognition
Shared title terminology · Manh Tuan Ha, Xuan Bao Viet Tran, Vo Minh Dat Nguyen et al.
What Does the Visual Encoder Buy? Visual Information Gain in Encoder-Free Multimodal Pretraining
Shared title terminology · Zhixuan Ge, Anqi Li, Wei Qiu
Extended KAFR: A kinematic-adaptive paradigm for the efficient analysis of surgical video
Shared title terminology · Huu Phong Nguyen, Shekhar Madhav Khairnar, Ganesh Sankaranarayanan