EfficientUICoder: Efficient MLLM-based UI Code Generation via Input and Output Token Compression

Jingyu Xiao, Zhongyi Zhang, Yuxuan Wan, Yintong Huo, Yang Liu, Michael R. LyuarXiv 2025 · DOI

Abstract

EfficientUICoder addresses the computational inefficiency of UI-to-code generation in Multimodal Large Language Models (MLLMs). By implementing bidirectional compression—targeting both input visual tokens and output code tokens—the framework reduces inference time and computational costs by nearly 50%. Key innovations include Element and Layout-aware Token Compression (ELTC) and Adaptive Duplicate Token Suppression (ADTS). Evaluations on Design2Code and WebCode2M benchmarks demonstrate that EfficientUICoder maintains high generation quality while significantly improving efficiency.

Introduction

The automation of converting UI screenshots into functional HTML/CSS code (UI2Code) represents a significant advancement in web development productivity. However, state-of-the-art MLLMs face two primary efficiency bottlenecks. First, "Input Bloat" occurs because high-resolution images are decomposed into thousands of visual tokens, many representing uninformative background regions. Second, "Output Redundancy" involves models generating repetitive CSS or HTML structures, inflating token counts and potentially breaking code functionality.

Methodology

EfficientUICoder introduces a bidirectional strategy to streamline the UI2Code pipeline, targeting both the encoding and decoding phases.

Element and Layout-aware Token Compression (ELTC)

Instead of treating an image as a uniform grid of patches, ELTC uses a UI element detection algorithm to identify critical regions such as buttons, text, and images. It then constructs a "UI element tree" using a Minimum Spanning Tree (MST) algorithm to preserve the essential layout hierarchy while discarding empty space.

Region-aware Token Refinement (RTR)

To ensure no subtle visual details are lost, RTR analyzes the model's internal attention scores. It prunes low-attention tokens from detected element regions and selectively re-integrates high-attention tokens from the "background" regions that ELTC initially ignored.

Adaptive Duplicate Token Suppression (ADTS)

During the code generation phase, the framework uses real-time HTML and CSS parsers to track the frequency of generated structures. If the model begins to repeat itself (e.g., identical CSS selectors), ADTS applies an exponential penalty to the probabilities of those tokens, forcing the model to break the cycle and continue with the rest of the webpage.

The EfficientUICoder pipeline, illustrating the flow from UI image to compressed visual tokens and final code generation.

Datasets and Evaluation

The researchers evaluated their framework using two prominent UI2Code benchmarks:

  • Design2Code: A dataset featuring 484 real-world webpage screenshots paired with original source code.
  • WebCode2M: A large-scale dataset for webpage code generation, tested using subsets of varying lengths (short, mid, and long).

Key Results

EfficientUICoder delivers significant efficiency gains across the board, particularly on 34B-parameter models:

  • Compression: Achieves a 55%-60% compression ratio for visual tokens.
  • Speed: Reduces prefill time by 46.6% and total inference time by 48.8%.
  • Cost: Lowers the total computational cost (FLOPs) by 44.9%.
  • Quality: Despite the massive reduction in tokens, the model maintained or improved its scores on metrics like CLIP (visual similarity) and BLEU (code similarity). Human evaluators consistently preferred EfficientUICoder's output over standard "Vanilla" models.

Discussion and Insights

A critical finding was the "attention distraction" phenomenon, where MLLMs often pay more attention to empty background areas than to actual UI elements. EfficientUICoder corrects this by anchoring the model's focus on detected elements. Furthermore, the authors identified an "inverted-U" relationship in token refinement: adding back 5-10% of unselected tokens improves performance, but exceeding that threshold re-introduces noise.

Limitations and Future Work

The framework currently requires modifying internal encoding and decoding logic, limiting its application to open-source models like the LLaVA-v1.6 series rather than black-box commercial APIs. Future work may involve extending these compression techniques to other multimodal tasks, such as video-to-code or interactive UI agent tasks.

Summary updated

BibTeX
@misc{xiao2025efficientuicoder,
  author = {Jingyu Xiao and Zhongyi Zhang and Yuxuan Wan and Yintong Huo and Yang Liu and Michael R. Lyu},
  title = {{EfficientUICoder: Efficient MLLM-based UI Code Generation via Input and Output Token Compression}},
  year = {2025},
  eprint = {2509.12159},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.12159},
}
Figure