All articles
Performance··11 min read

Your vibe coded app is slow. Here is where to look.

Read this one if it is slow right now. The index Postgres never created, the policy that runs once per row, the missing foreign key that forces a loop, and the one cause on every checklist that is not actually your problem.

A slow vibe coded app is almost never slow for a mysterious reason. It is slow because the database is reading rows it did not need to read, or because the browser is doing work it did not need to do. Both are findable in an afternoon, with tools you already have installed.

The order matters. Measure first, because the two halves have completely different fixes and guessing wrong costs you a day. Then work the database, because that is where the largest single wins are. Then work the browser, because that is where the most consistent ones are.

One warning up front. Of the three causes people usually name, one of them is mostly not a real problem on modern hosting, and chasing it wastes time. I will get to that.

First, find out which half is slow

Open the Network tab and reload. Look at the first request, the HTML document itself, and read its Waiting for server response time. That number is your server and your database. Everything after it is your browser.

If the document takes 1.8 seconds to come back, no amount of image optimisation will help you. If the document comes back in 90ms and the page still feels slow, your database is fine and you have a JavaScript problem. Nearly every wasted optimisation session starts by skipping this step.

Google's thresholds for the three Core Web Vitals, measured at the 75th percentile of real visits, are 2.5s for Largest Contentful Paint, 200ms for Interaction to Next Paint, and 0.1 for Cumulative Layout Shift. Server response under 0.8s is the supporting target. Those are the numbers worth holding yourself to.

The index your database did not create for you

Postgres creates an index for a primary key automatically. It does not create one for a foreign key. This is the single highest yield check on a generated schema, and it is documented plainly:

Since a DELETE of a row from the referenced table or an UPDATE of a referenced column will require a scan of the referencing table for rows matching the old value, it is often a good idea to index the referencing columns too. Because this is not always needed, and there are many choices available on how to index, the declaration of a foreign key constraint does not automatically create an index on the referencing columns.

· PostgreSQL documentation, Constraints

Read that against your own schema. Every user_id, org_id, project_id and post_id column is a foreign key. Every one of them is in a where clause on a hot path. None of them is indexed unless somebody wrote the index by hand.

Without one, the query does exactly what you would expect:

With no advance preparation, the system would have to scan the entire table, row by row, to find all matching entries. If there are many rows and only a few rows that would be returned by such a query, this is clearly an inefficient method.

· PostgreSQL documentation, Indexes

On Supabase this has a name and a dashboard. Open the Performance Advisor and look for unindexed_foreign_keys. If you would rather see it in SQL, this finds every foreign key column with no index on it:

select conrelid::regclass as table_name, a.attname as fk_column from pg_constraint c join pg_attribute a on a.attrelid = c.conrelid and a.attnum = any(c.conkey) where c.contype = 'f' and not exists (select 1 from pg_index i where i.indrelid = c.conrelid and a.attnum = any(i.indkey));

Two reasons your index test will lie to you

Your test table is too small. Postgres chooses a sequential scan when it is genuinely cheaper, and on a few hundred rows it always is:

It is especially fatal to use very small test data sets. While selecting 1000 out of 100000 rows could be a candidate for an index, selecting 1 out of 100 rows will hardly be, because the 100 rows probably fit within a single disk page, and there is no plan that can beat sequentially fetching 1 disk page.

· PostgreSQL documentation, Examining Index Usage

You never ran ANALYZE.The planner decides using statistics, and a table that was bulk loaded by a seed script has none. From the same page: “Examining an application's index usage without having run ANALYZE is therefore a lost cause.”

There is a real cost on the other side, so do not index everything. Indexes have to be kept in sync on every write. The lever you actually want is removing indexes nothing reads, not having fewer indexes. select relname, indexrelname, idx_scan from pg_stat_user_indexes where idx_scan = 0; lists the ones costing you writes and returning nothing.

If you are on Supabase, check this before anything else

Every AI tool writes row level security policies the same way, and it is the slow form.

A policy of using (auth.uid() = user_id) calls auth.uid() once per row. Wrapping the call in a subselect, using ((select auth.uid()) = user_id), changes the plan rather than the logic:

Wrapping the function causes an initPlan to be run by the Postgres optimizer, which allows it to cache the results per-statement, rather than calling the function on each row.

· Supabase documentation, Row Level Security

Same result, same security, one evaluation instead of a million. Supabase lints for it as auth_rls_initplan, at warning level. Two other things from the same guidance are worth doing in the same sitting: index the column your policy filters on, and add the filter to your client query too rather than leaning on the policy to do it. Supabase is blunt that leaning on it is the mistake: “Policies are implicit where clauses, so it's common to run select statements without any filters. That's a bad pattern for performance.”

Supabase publishes a benchmark for these fixes showing changes like 171ms to under 0.1ms, and one cross-table case going from 178 seconds to 12ms. Treat the shape as real and the magnitudes as indicative. The stated methodology is only “selects on a 100K row table,” the compute size is never given, and the figures are single EXPLAIN ANALYZE runs rather than repeated measurements. It was contributed by a community member and adopted into the docs. Supabase's own materials quote the speedup variously as 5 to 10 times, 100 times, and several thousand times, which tells you the number depends entirely on your data. Measure your own.

One honest limit, in their words: the subselect trick only works “if the results of the query or function do not change based on the row data.” A policy that genuinely depends on each row cannot be hoisted.

One query per row

This is the classic, and it is real. Prisma defines it precisely: “The n+1 problem occurs when looping through query results and performing one additional query per result.” Fetch 50 posts, loop over them to get each author, and you have made 51 round trips where 2 would do.

What is more interesting is why it happens on Supabase specifically, because it is a chain you can break at the start.

PostgREST, the layer behind the Supabase client, can fetch related rows in one request. Supabase describes the result as resolving “all requests to a single SQL statement.” So select('*, author(*)')is one query, not fifty one. But PostgREST documents the precondition: “The server uses Foreign Keys to determine which database objects can be joined together.”

Now look at a generated schema. If the table was created with a bare user_id uuid and no referencesclause, there is no foreign key. The embed fails with “Could not find a relationship,” the developer sees an error, and the obvious way out is a loop. The missing constraint causes the N+1.

So declaring the foreign key fixes two things at once. It makes the single query possible, and it is the column you were going to index anyway.

Compression is not your problem

Here is the one worth unlearning. “Uncompressed assets” is a standard item on every performance checklist, and on modern hosting it is close to a non issue, because you cannot turn it off:

  • Netlifyhas applied Brotli automatically since 2020, with “no additional config required or possible.”
  • Cloudflare states that content is compressed by default, across more than forty content types including web fonts.
  • Vercel applies gzip and Brotli automatically to text content.

Vercel also explains why images are excluded, and it is the part people miss: “most image formats are already compressed such as JPEG, PNG, WebP.” Running gzip over a JPEG achieves nothing. There is no compression win available on your images, because it has already been taken.

If a Lighthouse run still tells you to enable text compression on one of those three hosts, that is unusual and worth investigating rather than fixing blindly.

What people are actually seeing when they blame compression is two different problems, and both are about quantity rather than encoding.

Problem one: the image is too big, or discovered too late

This matters more than it sounds, because on most pages the image is the metric. In the 2025 HTTP Archive crawl of roughly 16.2 million sites, the Largest Contentful Paint element was an image on 76.0% of mobile pages and 85.3% of desktop pages. Median image weight was 911KB on mobile, the largest resource category on the page.

There are three separate failures here and they need different fixes:

  • Weight. A 2400px image in a 400px slot. Costs you load time.
  • Discovery. The browser finds the image late, so the download starts late. Costs you more, usually.
  • No reserved space. Content jumps when the image lands. Costs you layout shift.

Two specific things to check, both of which generated code gets wrong routinely.

Never lazy load the image at the top of the page.Google states it without hedging: “Never lazy-load your LCP image, as that will always lead to unnecessary resource load delay, and will have a negative impact on LCP.” The mechanism is the part that surprises people: the browser cannot lazy load an image until it knows where that image will sit, which means it has to wait for your stylesheet. You have put CSS in front of your hero image. Note that next/image defaults to lazy loading, so this is the default behaviour rather than a mistake someone made.

A fill image without a sizes attribute downloads a full width image every time. From the Next.js documentation: “If sizes is missing, the browser assumes the image will be as wide as the viewport. This can cause unnecessarily large images to be downloaded.” Grep your codebase for fill and check each one.

A related trap. Lighthouse's Next.js advice still tells you to set priority on your LCP image and links a documentation page that predates the App Router. That prop is deprecated in Next 16, which now points you at loading="eager" or fetchPriority="high" instead. Doing what the tool says will hand you a deprecation warning.

Problem two: the JavaScript

This is the one with the most alarming number attached to it, and it comes from a neutral source rather than a vendor. In the HTTP Archive crawl of September 2026, across 15.47 million mobile URLs, the median page spent 3.73 seconds of CPU time executing JavaScript. Median JavaScript transfer weight was 689KB.

The Web Almanac's own framing of why this is different from image weight is the clearest statement of the principle: “100 KB of an image is just pixels, but 100 KB of JavaScript is work.”

In a Next.js app the usual cause is a single misplaced directive. The rule is mechanical: “Once a file is marked with "use client", all of its imports and the components it directly renders are included in the client bundle.”

Put that on a layout and you have just shipped that layout's entire import tree to every visitor. Nothing errors. Nothing warns. The page works. It is just slower to respond to clicks, because the browser is parsing and hydrating code it never needed. Move the directive down to the small interactive leaf that actually needs it, and pass server rendered output through as children.

To find it rather than guess, run npx next analyze, sort client modules by size, click the largest, and read the import chain. You are looking for a chain whose root is a layout or a page rather than a button.

The waterfall

Two awaits in a row are two round trips in a row. The Next.js documentation is explicit:

Within any component, multiple async/await requests can still be sequential if placed after the other. Requests begin as soon as fetch is called.

· Next.js documentation, Fetching Data

If the second query does not need the first one's result, start both and await them together with Promise.all. If it does, the waterfall is real and you need a different query.

The browser side version of this is fetching inside useEffect. React argues against it in its own documentation, and the second reason is the one that costs you:

Fetching directly in Effects makes it easy to create network waterfalls. You render the parent component, it fetches some data, renders the child components, and then they start fetching their data. If the network is not very fast, this is significantly slower than fetching all data in parallel.

· React documentation, useEffect

React also points out that effects do not run on the server, so the initial HTML contains a loading state and no data, and the visitor downloads your entire bundle before the first request is even sent.

The fix that takes one minute

Check what region your database is in, and what region your functions run in. Vercel functions default to iad1 in Washington DC. If you clicked through a Supabase setup and picked a region near you, those two may be on different continents.

Vercel's own worked example: a function in Sydney talking to a US East database and making three lookups spends “over a full second” on database queries alone. This is the one that multiplies. Ten serial queries across an ocean is seconds of pure network before anybody has computed anything. It is also the cheapest thing on this list to fix, because it is a setting rather than a code change.

Cold starts are probably not your problem

Cold starts attract an enormous amount of attention relative to the evidence for them, and the most useful corrective comes from an AWS engineer talking about Lambda at re:Invent, which is not where you expect to hear it.

I can't talk about cold starts without acknowledging the truth, that this is a 1% phenomena.

· AWS re:Invent 2023, Demystifying Lambda cold starts

In the same talk: for one function they examined, almost 80% of initialisations did not increase user-facing latency at all. What did help was importing less, with a measured example where loading an entire SDK cost 540ms and importing only the one client needed cut 400ms off that. And on the most popular workaround, he said he would not encourage you to use warmers.

For Vercel specifically, be careful what you believe, because the numbers in circulation have no source. Vercel publishes no cold start duration distribution at all, no median and no percentiles. The frequently quoted 280ms is a value in an illustrative screenshot in a changelog, not a benchmark. I could find no origin whatsoever for the common claims of 250ms, or of one to three seconds.

Their documentation is more restrained than their marketing: Fluid compute reduces cold starts through instance reuse and pre-warming, and the docs say plainly that cold starts can still happen during periods of low traffic. Never eliminated.

If it matters to you, measure it. Runtime logs label every invocation as hot, pre-warmed or cold, with a duration. Two gotchas if you do: bytecode caching applies only to production, and pre-warming is paid plans only, so benchmarking on a free preview URL measures a different system from the one your users hit.

Where the evidence actually stops

I want to be straight about what is and is not established here, because the honest version is more useful than the confident one.

What is well established: every mechanism above. Unindexed scans, per row function calls, N+1, bundle size, lazy loaded hero images and request waterfalls are all documented by the people who build Postgres, React, Next.js and Chrome. Fixing them makes apps faster. That part is not in question.

What is established but narrower than it sounds: there is peer reviewed work finding that language model generated code is slower than expert human code, roughly two to three times slower on execution, or reaching about 45% to 62% of expert efficiency depending on the measure. Those studies test LeetCode and HumanEval puzzles. Several say so in their own limitations sections. A 2026 reanalysis that re ran all four major benchmarks with repeated executions and significance testing found that under their original test suites, only 6.11% of the supposedly faster implementations were statistically faster at all.

What is not established at all: that AI tools specifically produce the failures in this article. Nobody has counted N+1 queries, missing indexes or misplaced client directives across AI generated codebases. The one empirical study of AI generated SQL I could find pointed slightly the other way: it found select * rare, and reported that every model included the necessary limits. Its actual finding was about missing partition filters.

So I am not going to tell you AI writes slow code. The defensible claim is narrower and more useful. These are the documented ways a Next.js and Supabase app gets slow. AI tools generate code faster than anybody reviews it, and they work from training data that demonstrably predates current framework defaults, which is a staleness problem rather than a competence one. Vercel and Supabase both now ship rule files that force feed exactly these items into every agent session, ranking missing indexes, connection pooling, waterfalls and bundle size as critical. That tells you which known mistakes they thought worth intercepting. It does not tell you the model invented a new one.

The order to work in

  • Measure. Network tab, first request, server response time. Decide which half you are fixing.
  • Open the Supabase Performance Advisor and fix every warning. Highest return per minute on this list.
  • Index your foreign keys. Nothing did it for you.
  • Wrap auth.uid() in a subselect in every policy where the result does not depend on the row.
  • Declare foreign keys so you can replace loops with a single embedded query.
  • Check your regions match. One setting.
  • Stop lazy loading the hero image and add sizes to every fill.
  • Run npx next analyze and find the "use client" that is higher up the tree than it needs to be.
  • Prove it with EXPLAIN. explain (analyze, buffers) select ..., and watch Rows Removed by Filter. A policy that discards most of the table on every read is a policy whose filter column needs an index.

One gotcha for anyone copying a pg_stat_statements query off a blog. Postgres 13 renamed total_time and mean_time to total_exec_time and mean_exec_time. Any snippet using the old names predates 2020 and will simply error on a current Supabase database.

Find out which of those apply to you

Fourteen questions, about three minutes, runs entirely in your browser. You get a ranked list of what's actually open, with the fix for each.

Run the free check

Sources

Quotations from the two interviews are transcribed from the published videos and lightly condensed for readability.