i was building a simple dashboard. nothing fancy.
just fetch some user data and display it.
opened it to test something and just stared at
my screen for almost a minute. 47 seconds to load.
for 200 users.
first i did what every developer does. checked the
network tab. refreshed 3 times. blamed my wifi.
still 47 seconds.
so i stopped guessing and used an AI prompt to
find the problem.
here's the prompt i used:
"Act as a performance engineer. This code is running
slower than expected. The app loads a dashboard that
fetches user data. With 100 users it loads in 200ms.
With 10,000 users it takes 45 seconds and sometimes
crashes. Identify the bottleneck, explain why it's
slow, and rewrite an optimized version with comments
on what changed."
the response was not what i expected.
i was making 3 separate database calls inside a loop.
one for the profile, one for orders, one for last
login. per user. every single time someone opened
the dashboard.
sounds fine when you write it. its not fine when
you do the math.
200 users = 600 queries. 10,000 users = 30,000 queries.
it has a name apparently. the N+1 query problem. one
of the most common performance bugs in backend
development and i had genuinely never heard of it.
the before and after is kind of embarrassing:
45 seconds to 200ms. the fix replaced the loop with
3 parallel bulk queries using Promise.all. instead of
hitting the database once per user it fetches
everything in one shot for all users at once.
6 changes. maybe 20 minutes to implement.
the thing that got me is this code looked completely
normal. readable. clean even. no red flags. it just
happened to be silently destroying performance at
any kind of scale.
i would have never found this by staring at the code.
i had been looking at it for days.
lesson: working code and fast code are not the same thing.
going to keep running these prompts on the rest of
the codebase. slightly terrified of what else i'll find.
if you want to try this on your own code just copy
the prompt above and paste your actual function
instead of mine. i have 99 more prompts like this
organized by category here 👉 https://payhip.com/b/i7IZa




Top comments (0)