Why Your AI-Built App Gets Slower as It Grows (and How to Find the Cause)
Your app was fast at launch. A few months and a few thousand records later, the main page drags, and nobody changed that code.
Often the code is not broken. It does extra work for every row it reads. On small data that work is invisible. On real data it is the whole wait.
The case: 17 unzips per job
An AI wrote the job list in a job-alert app I build and run. It looked right and it was fast with few jobs.
Each saved job keeps the job board’s full record: description, client spend, rating, hires, country. About 3 KB.
Postgres, the database, compresses any value over about 2 KB and keeps it in a side table, like a zip file. To read one thing from it, Postgres fetches the whole file and unzips it. It does not keep the unzipped copy.
The list showed 17 values per job, like client rating and client spend. So it unzipped the same file 17 times per job. Nothing in the code hints at that: it reads like 17 small lookups.
It also did this for every saved job in the last two weeks, about 1,700, then kept only the 100 it shows. About 30,000 unzips for one page.
How I found it
I did not guess. I timed the page’s server request first: 535–791 ms. Then I timed the slowest database read inside it: about 270 ms, almost all of it spent unzipping.
The fix
- The 17 values became plain columns, worked out once when a job is saved. The list never unzips.
- The list now picks its 100 jobs first, then reads their details.
On a copy of the real data, that read went from about 200 ms to 12 ms, with the same 100 jobs.
Then measure again
With the big step gone, I added a timer to every step of the request. The next biggest waits were not where I would have guessed:
| Step | Time | Fix |
|---|---|---|
| Asking the sign-in service for the user’s email | 86–206 ms, every request | Remember it for 5 minutes |
| Server and database in different cities | a little on every database trip | Run the server next to the database |
| An “is this account set up?” check | several trips, every request | One quick lookup |
After all four fixes, the whole request takes 65–78 ms, down from 535–791 ms.
One fix I planned and dropped: the timers showed the remaining reads take about 60 ms, too little to be worth the work.
Check your own app
You can ask for these without reading code:
- Which step takes the time? Ask for a timer on each step, not a guess. The slow part is often not the one everyone suspects.
- Was it tested with real-size data? Code that is fast with 50 rows can be slow with 5,000. Test on a copy of real data, with personal details removed.
- Does it read more than it shows? A page that shows 100 items should not process 1,700 to get there.
- Does every request call an outside service? Sign-in, payments and email providers each add a trip. Some answers can be remembered for a few minutes.
- Do the server and the database live in the same region? Every database trip pays the distance.
Skip all this if the page feels fast and your data is small. Measure when it starts to drag, before anyone rewrites anything.
More on what changes as users grow: SaaS scaling readiness checklist.
AI writes code that works. I find where it breaks at real size, measure it, and fix that step, without rebuilding the app.
The short version
An app that slows down as it grows is usually doing hidden work per row. Time each step, fix the biggest one, then time again.
Which page in your app got slower as your data grew?
Stack: Next.js on Vercel, Postgres on Neon, Clerk for sign-in.
The slow read
The list grouped every sighting of a job (one job can be found by several searches) and took each fact from the newest sighting:
(ARRAY_AGG(seen.details->'client'->>'totalFeedback'
ORDER BY seen.last_seen_at DESC))[1] AS client_rating
Seventeen of those, each reading the same jsonb column. The column averages about 3 KB, so Postgres stores it TOASTed: compressed, out of line. Every -> on it detoasts it again. EXPLAIN (ANALYZE, BUFFERS) on the live data: 1,742 rows grouped into 1,332 jobs, 136,000 buffer hits, 268 of 270 ms in the GroupAggregate. Then LIMIT 100.
The fix
Generated columns. Worked out once on write, so every write path stays correct with no app code:
ALTER TABLE job_sightings
ADD COLUMN client_rating numeric GENERATED ALWAYS AS (
CASE WHEN (details->'client'->>'totalFeedback') ~ '^[0-9]+(\.[0-9]+)?$'
THEN (details->'client'->>'totalFeedback')::numeric END
) STORED;
All 17 go in one ALTER TABLE, so the table is rewritten once.
Pick the page first. A CTE groups on cheap columns (status, times, which searches) and applies ORDER BY ... LIMIT 100. Only then does each picked job join its newest sighting for the facts:
WITH picked AS (
SELECT seen.job_id, ...,
(ARRAY_AGG(seen.id ORDER BY seen.last_seen_at DESC))[1] AS newest_id
FROM job_sightings seen ...
GROUP BY seen.account_id, seen.job_id
ORDER BY ... LIMIT 100
)
SELECT picked.*, seen.client_rating, ...
FROM picked
JOIN job_sightings seen ON seen.id = picked.newest_id;
On a copy of the real data (7,595 sightings): about 200 ms before, 12 ms after, identical rows.
Step timers
A small helper wraps each step and adds <step>Ms fields to the request’s closing log line:
export async function timeStep<T>(name: string, fn: () => Promise<T>): Promise<T> {
const context = requestContext.getStore(); // AsyncLocalStorage
if (!context) return fn();
const started = performance.now();
try {
return await fn();
} finally {
const steps = (context.steps ??= {});
steps[name] = (steps[name] ?? 0) + Math.round(performance.now() - started);
}
}
A live line after the first fix: ms 196, clerkMs 124, accountMs 4, setupMs 4, readsMs 60. The Clerk user lookup ran on every browser request.
The three smaller fixes
- Clerk email: kept in memory per server copy for 5 minutes, the rule the extension’s sign-in already used. A fresh copy still asks once.
- Region: functions moved from
iad1tocle1, next to the Neon database inus-east-2. - Account setup check: one
SELECTon the setup row; the setup transaction runs only when it is missing, and its insert-or-nothing still settles two first requests racing.
Result: the request went from 535–791 ms to 65–78 ms. The remaining reads (about 60 ms) were left alone.
More Posts
All posts
November 25, 2026
Why Your App Went Offline on Vercel's Free Plan (and How to Stay Under the Limits)
Vercel's free plan pauses every site on the account when one monthly limit runs out. What the limits mean in plain words, what uses them up, and the fixes, from a real case.
November 24, 2026
Why Your Project Starts With a Small Paid Step: Requirements and an Estimate Before the Build
A price given before the work is measured is a guess, and someone pays for it later. What a small paid first step gets you: written decisions, a cost range and a time range, and the choice to stop there.