Spark
Vibe coding: from idea to production

Refactoring and performance of a vibe-coded project

Topic 316 min read + 40 min for the taskRevised October 10, 2026

The “Reading and debugging the agent’s code” topic is about what to do when something has clearly broken. This topic is about the neighboring situation. The project works and looks right, but over time it gets slower or harder to grow, even though there’s no obvious error anywhere. The agent writes code fast and under pressure from a specific task, so it piles up the same compromises as a person in a hurry: repeated logic, bloated files, unoptimized images. Each compromise on its own is small. Together they make the project slower for the user and harder for the agent itself in the next session. The good news: you don’t need to fix this by hand. You just need to notice it in time and ask the agent.

What refactoring is and why a designer needs it

Refactoring means changing how the code is built inside without changing how the product looks and works from the outside. The user gets the same result, while the internal structure becomes clearer and easier to manage. You don’t need to know how to do it by hand. What helps is recognizing the moment to ask the agent for it. The first signal already came up in the “Reading and debugging the agent’s code” topic: a huge file hundreds of lines long. Here are a few more:

  • You keep having to explain the same thing again. Editing a product card means fixing three different places in the code, because a similar component was copied instead of reused. That’s a sure sign it’s time to move the shared part into one place.
  • Simple edits started taking longer. A small change used to take one prompt. Now the agent touches something nearby every time, and you have to roll back (the “Reading and debugging the agent’s code” topic). Often that’s not the agent’s fault but a symptom that the structure around it has become too tangled.
  • The same visual pattern looks slightly different in different places. The same card or button differs by a pixel in different parts of the product. Most likely it isn’t one reusable component but several similar copies that quietly drifted apart.

Refactor in the same small, checkable steps as any other edit (the “Vibe coding: websites” topic, section “When the result is off”). One refactoring pass at a time. A screenshot of the interface before and after, to make sure nothing changed visually even though a lot changed inside.

Go through this project and find repeated logic or similar components that should be pulled out into reusable ones. Don't change anything about how the app looks or works — only the internal structure
This file has grown too big — split it into a few smaller logical files, keeping the behavior exactly the same. Show me a list of what moved where

Performance: measure it instead of eyeballing it

“It’s fast for me” isn’t a metric yet. A designer usually has a powerful computer and good internet, and some real users don’t. Before you optimize anything, measure once what’s actually happening:

  • Lighthouse is a free audit tool built into Chrome’s DevTools (the “Reading and debugging the agent’s code” topic). You open the Lighthouse tab, run the analysis and get a numeric score for the page along with a list of specific findings: what exactly slows it down.
  • Core Web Vitals are three specific metrics Google uses to measure how fast a site feels to real users. The first is how fast the main content appears on screen (LCP). The second is how responsive the page is to user actions, clicks, taps and typing, throughout the whole visit (INP; in 2024 it replaced the older “first input delay” metric, FID). INP isn’t in the Lighthouse report — it’s measured on real users (PageSpeed Insights), and Lighthouse shows TBT instead. The third is how much page elements “jump” while loading (CLS). You don’t need to memorize the exact names. It’s enough to know that behind the vague phrase “the page feels slow” there are measurable numbers, not just a subjective impression.
  • The Network tab (the “Reading and debugging the agent’s code” topic) shows how many requests go out when the page loads and how much each one weighs. It helps when you can’t tell whether the page itself is slow or one specific heavy file on it.

A practical habit: measure before and after instead of trusting a feeling. Run Lighthouse before you ask the agent to change anything, and save the result. After the change, run it again and compare the numbers. The overall score swings noticeably even without edits, and a dev server gives different numbers than a production build. So measure the same production build with the same preset, do three runs each and compare the median of one specific metric, like LCP, not the overall score. It’s the same “lock it in and compare” principle as in the “Vibe coding: art and tools” topic for generative graphics, just applied to speed instead of visual parameters.

Chrome with the DevTools panel open on the Lighthouse tab: four circular scores, and below them a Metrics block with First Contentful Paint, Largest Contentful Paint, Total Blocking Time, Cumulative Layout Shift and Speed Index
A Lighthouse report in the DevTools tab. For a before-and-after comparison, look at the Metrics block instead of the overall score: Largest Contentful Paint first of all. · Lighthouse · screenshot: Chrome for Developers, CC BY 4.0
Build the production version of the project and run it locally. Then run npx lighthouse <page URL> three times with the same preset and show me the median LCP, CLS and overall score, plus the three most critical issues. If Chrome isn't found or the command won't run, tell me — don't make up numbers

A caveat: not every agent has access to a browser. A terminal agent can run Lighthouse from the command line or through a connected browser MCP server (Chrome DevTools MCP, for example). A web agent like v0 most likely can’t. If the agent says it can’t run the audit, run Lighthouse yourself in the DevTools tab and paste the report text to the agent. It can still fix the findings.

How to optimize: prompt examples

Optimizing is also a targeted edit, not one big overhaul. Ask the agent to fix Lighthouse findings one at a time, starting with the most critical. Don’t try to fix everything at once in a single prompt.

Almost always start with images: they’re the heaviest part of the page and the easiest fix. For scale: one 1600-pixel-wide cover weighs about 1.3 MB as PNG, 110 KB as JPEG and 50 KB as WebP. AVIF squeezes it down to 40 KB. To the eye, all versions look the same, but the difference in weight is 25x. Keep PNG for icons, logos and images with transparency, and convert photos and covers to WebP.

  • “The images on this page are noticeably heavy — compress them and convert them to a modern format (WebP or AVIF) without visible quality loss”
  • “Run an audit for unused code and dependencies that bloat the final bundle size, and suggest what can be safely removed”
  • “This page has a lot of content below the first screen — can it be lazy loaded so it doesn’t slow down the initial load”
  • “Measure this page’s Lighthouse score before and after you add the new map block — show me whether anything got worse, and if so, what exactly”

Command examples for practice

Where to pasteTerminal agent or Cursor, from the project folder
Find two similar but not identical card components in this project and suggest how to merge them into one reusable component without changing how either card looks
Refactor this specific component (paste the path) for readability: rename unclear variables, remove dead code — but don’t touch the logic
Where to pasteAny chat assistant: ChatGPT, Claude, Gemini
Explain in plain words the difference between Core Web Vitals and just ‘the site opens fast’ — as if I’ve never done any optimization
Where to pasteThe agent in the project — together with the Lighthouse report as JSON or a list of failed audits: the HTML report weighs hundreds of kilobytes and won’t really fit in a chat
This page has a low Lighthouse score for images — show me a list of the heaviest files and suggest what to compress first
Mini-task

Run Lighthouse on any of your vibe-coded projects. Write down the current score and the top three findings. Ask the agent to fix just one of them, then run Lighthouse again and compare what actually changed in the numbers, not by eye. Measure the production build, three runs before and after, and compare the median of one metric.

Time: 40 minutes
Done when: you have three Lighthouse runs before and after one fix on the same build, and the median of a specific metric changed

Sources

  1. Web Vitalsweb.dev

    the three Core Web Vitals metrics and their thresholds

  2. Interaction to Next Paint becomes a Core Web Vital on March 12web.dev

    INP replaced FID on March 12, 2024

  3. Lighthouse performance scoringdeveloper.chrome.com

    what makes up the Lighthouse score, TBT instead of INP

  4. Lighthouse Variabilitygithub.com

    why the score fluctuates and why you take the median of several runs

  5. Chrome DevTools MCPgithub.com

    the official Chrome DevTools MCP server for agents

Found a mistake or an outdated fact? Write to hey@iskra.guide