When a model builds a website from a stack of design screenshots (several pages, each drawn at desktop, tablet and mobile widths), most of what it looks at repeats. The navigation bar, the footer, the product card and the login form appear again and again. Two things currently go wrong at once. First, the model pays for every repeat: each screenshot becomes hundreds or thousands of "visual tokens" (the patch embeddings a vision encoder hands to the language model), so a dozen screenshots overflow memory and slow the first response. Second, the model writes every repeat again as code: each page file gets its own copy of the header instead of importing one shared component. That is the cross-file failure behind broken multi-page sites and duplicated logic. This note argues that these are one problem. A region that repeats across screenshots is both a wasted visual token and a missing shared file. Detecting it once can therefore shrink the input and give the code its file structure.
Concretely, we propose to match near-duplicate regions across all prototype images of a task, encode each repeated region once, and replace its other occurrences with a few "component reference" tokens that carry an identity, a bounding box and a viewport tag. A compact vision-language model, specialized for this format, is trained to emit one file per discovered component and page files that import those components. The claim we test is that this beats per-image token pruning at the same token budget on multi-page benchmarks, on functional correctness and on code structure, not only on speed. The structural gain is the part no efficiency method offers.
What exists and where the gap is
The setting is defined by Vision2Web, a benchmark of 193 website-building tasks with 918 prototype images across three viewports and three levels: static pages, multi-page interactive frontends, and full-stack systems. It reports a "complexity wall". Models that score well on single pages fail at higher levels because of cross-file integration errors, and visual fidelity drops 10–20% on dense mobile layouts. The paper diagnoses the problem but proposes no method. That motivates us. The two strongest specialized UI generators both stop at one file. UI2Code^N trains a 9B model with pairwise visual reinforcement learning and reaches 88.6% on Design2Code-HARD. Figma2Code compiles design metadata into an intermediate representation for a single Tailwind page, and it shows that feeding raw layout metadata makes models copy absolute coordinates instead of writing responsive CSS. Both show that a compact, domain-specialized model is a viable base. Neither touches multiple pages or multiple files. We reuse their recipe and change the input and output structure.
On the token side, DART shows that removing duplicate tokens relative to a few pivot tokens works better than keeping attention-"important" ones. It prunes 88.9% of tokens on LLaVA-1.5-7B while retaining 98.8% of performance. LOOK-M merges evicted visual key-value cache entries into kept ones during long multimodal contexts. CARES picks the smallest sufficient input resolution per query. FEATHER warns that early pruning can carry spatial biases. All four work within a single image or a single stream and treat duplicates as waste to throw away. We supply a cross-image matching step, and we keep each duplicate's identity instead of discarding it. DART's result also constrains our design: it argues against importance scoring, so our matching uses feature similarity plus spatial coherence and not attention.
On the code side, RepoGraph and RPG/ZeroRepo show that explicit dependency graphs beat flat retrieval for repository work. RepoGraph raises file localization from 47.3% to 51.7% on SWE-bench Lite. RPG reaches 81.5% functional coverage on RepoCraft through graph planning. Both build their graphs from existing text code. In design-to-code there is no code yet, so the graph has to come from the pixels. Le Hai et al. document that models without cross-file awareness re-implement existing functionality. This is exactly the duplicated-header smell we aim to remove. LongCodeU reports a sharp reasoning decline past 32K tokens, failing on relations between units. That argues against simply concatenating every screenshot.
Core Claim
Cross-page visual redundancy is a usable signal of software structure. If the system deduplicates prototype screenshots across pages and viewports, it should cut visual tokens roughly in proportion to how much the pages share. If each repeated region is also exposed to a specialized model as a named component, the model should produce multi-file code that is more functionally correct and less duplicated than the same model given per-image-pruned inputs at an equal token budget.
The token accounting is simple. A task has $N$ images of $T$ tokens each. Suppose a fraction $r$ of each image is covered by shared components, each component reference costs $p$ tokens, and there are $m$ references in total. Then the visual input drops from $NT$ to roughly
$$NT(1-r) + rT + mp,$$
where the single $rT$ term counts each shared region once. The saving grows with $N$, which is why we expect the method to help most on Level 2 multi-page tasks and least on single pages.
Research Program
The pipeline has three parts.
The first part is cross-image component discovery. It runs the vision encoder on every prototype image at native resolution. Encoding is cheap compared with language-model prefill. It then finds groups of patches whose features are near-duplicates across at least two images and that form spatially contiguous regions with consistent internal layout. Matching across viewports is the hard case, because a desktop header and its mobile version are not pixel copies. We handle this by matching at several pooled scales and by linking regions whose content features agree even when their geometry differs. Those links are recorded as breakpoint variants of the same component, not as separate components. The output is a component graph: nodes are components with one canonical token set each, and edges record which page contains which component, where, and at which viewport.
The second part is the input format. Canonical component tokens appear once, in a shared prefix, so their key-value cache can be computed once and reused while every file is generated. Each page keeps its unique tokens and receives a short reference token sequence wherever a component sits. Near-duplicates whose content differs, such as a navigation bar with a different highlighted item, keep a small residual set of tokens covering the differing patches. This prevents silent merging of states that the code must actually distinguish.
The third part is specialization. We fine-tune an open compact vision-language model, of the size class UI2Code^N uses, on synthetic multi-page sites. We build these by composing open-source front-end components into multi-page projects and rendering each page at three viewports. This yields the true component graph for free. Training targets are multi-file projects: one file per component and page files that import them. We then add a reinforcement learning stage whose reward combines the rendered visual similarity used by UI2Code^N, the fraction of functional tests passed, and a penalty for duplicated markup across files. Exposing breakpoint variants of the same component together should also push the model toward one responsive component instead of the hard-coded coordinates Figma2Code observed. We will measure this directly rather than assume it.
Baselines
The naive reference is the same specialized compact model given every prototype image at full token count. Where memory forces it, images are downsampled until the input fits. This shows what deduplication buys over doing nothing, and it is fair because the model weights, training data and decoding budget are identical. It also yields the latency and peak-memory figures that every other row is compared against.
The strongest efficiency competitor is per-image DART. Its cosine-similarity deduplication against a small pivot set is the best duplication-based pruning in the file: 98.8% of performance retained at 192 tokens with 88.9% pruned on LLaVA-1.5-7B, as reported by DART. We apply it image by image so that the total visual tokens per task exactly match our method's budget. The base model gets the same fine-tuning data, re-formatted for pruned inputs, and the same tuning budget. Beating it means higher Vision2Web functional pass rate and lower duplicated-code ratio at equal tokens. Merely matching it on visual score would not count. We also run CARES-style resolution selection CARES at the same budget, since it is the strongest upstream alternative and is exposed to mobile-density failures.
The strongest generation competitor is per-page single-file generation in the UI2Code^N style, which reports 88.6% on Design2Code-HARD UI2Code^N. Each page is generated independently, and then a frontier text model is asked to refactor shared parts into components. On Figma2Code we additionally compare against F2CAgent, reported at VES 0.7990 against 0.6801 for direct prompting Figma2Code. For Vision2Web itself there is no reported result found on Lacuna for an absolute leading score, so we will run all baselines ourselves under the benchmark's dual verifier.
Two ablations isolate the key ingredient. The first keeps our cross-image deduplication but drops the duplicates without leaving identity-bearing reference tokens. This has the same token savings and no structural signal, so any gap between it and the full method measures the value of "redundancy as architecture" rather than of compression. The second replaces discovered components with the ground-truth graph from synthetic data, or with Figma's declared component instances where they exist. This bounds how much discovery errors cost.
Why not just…?
Why not just prune each image with DART and let the model figure out the components? Within-image deduplication removes repeated background inside a screenshot but cannot notice that page three's header equals page one's. Token cost therefore still grows linearly in the number of pages, and the model receives no hint that a shared file is warranted. The direct test is the matched-budget comparison above. If per-image DART ties us on functional pass rate and duplication, the structural claim fails and we would report the method as a pure efficiency gain at best.
Why not just ask the model to write a component plan in text first, then generate code? This is the real threat to the structural half of the claim, because plan-then-code is how RPG succeeds on text repositories. However, the planner still has to see all screenshots, so it hits the same token explosion and the long-context decline LongCodeU reports. Its plan is also a guess, not grounded in matched pixels. We run this baseline with the same compact model and token budget, using downsampling to fit. If it matches the full method, the honest conclusion is that deduplication helps efficiency, while structure can come from planning. We would then narrow the paper accordingly.
Why not just use the component definitions already in design files? Where Figma metadata exists, declared component instances are a better signal than our matching, and we use them as the oracle ablation. Two caveats apply. Vision2Web supplies only images, which is the common real case. Figma2Code also shows that raw metadata invites copied coordinates. Our method targets the screenshot-only regime, and the oracle row shows how far discovery sits from it.
Why not just use a frontier model with a very long context window? LongCodeU's 32K-token decline and Vision2Web's collapse at Level 3 both indicate that capacity to hold the input is not the bottleneck. We include one long-context frontier run on Level 2 as a reference point and do not rely on it.
Proposed Experiments
The main evaluation is Vision2Web Levels 1–3, scored with its GUI-agent functional tests and VLM visual judge. Level 2 is the primary target, Level 1 should show little benefit, and Level 3 tests whether cleaner frontend structure reduces integration failures. Alongside these scores we report visual tokens per task, prefill compute, time to first token and peak key-value memory. We add two structural measures. The duplicated-markup ratio across output files is the smell Le Hai et al. describe. Component reuse is checked against the discovered graph. On synthetic held-out sites, we measure discovery precision and recall against the true component graph, including false merges of differing states. On Figma2Code we report VES, MAE, absolute-positioning ratio and arbitrary-value usage, to test whether seeing breakpoint variants together reduces hard-coded coordinates. On Design2Code-HARD we check that single-page quality does not regress relative to the 88.6% reference.
Three outcomes would settle the question. The first is the identity ablation. If keeping reference tokens does not beat dropping duplicates at equal budget, the core claim is false. The second is the scaling curve. Token savings and the gap over per-image DART should grow with the number of pages per task, as the accounting predicts; a flat curve would mean the discovery step is not finding real cross-page sharing. The third is the error analysis of false merges. If merged-but-different components account for a large share of functional test failures, residual tokens are insufficient, and the matching threshold, not the idea, is the limit to fix next.
References
- Vision2Web: A Hierarchical Benchmark for Visual Website Development with Agent Verification
- UI2Code$^{\text{N}}$: UI-to-Code Generation as Interactive Visual Optimization
- Figma2Code: Automating Multimodal Design to Code in the Wild
- Stop Looking for "Important Tokens" in Multimodal Language Models: Duplication Matters More
- LOOK-M: Look-Once Optimization in KV Cache for Efficient Multimodal Long-Context Inference
- CARES: Context-Aware Resolution Selector for VLMs
- Feather the Throttle: Revisiting Visual Token Pruning for Vision-Language Model Acceleration
- RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graph
- RPG: A Repository Planning Graph for Unified and Scalable Codebase Generation
- On the Impacts of Contexts on Repository-Level Code Generation
- Benchmarking Long-Context Language Models on Long Code Understanding