Performance advice
So I have some queries that are taking over 15 seconds to run on vercel serverless with postgres supabase and brevo emails.
This is an example
https://gist.github.com/samducker/15c3c8e2e70cd86d0721cc584da0901b
So I already went ahead and created relevant indexes on the tables, and the parts of the request that can be parallelised are. However I wonder why this might still be so slow?
I did console time to check the email request is quite slow at 3 seconds. But it still doesnt plain why the request takes 15 secs in total.
Can I log the SQL that is generated somehow? Any advice on how best to investigate further what is the cause? Should I put the email part in a queue?
p.s. many of my other requests are much more performant.
7 Replies
I would say that you need to identify which one of those statements is dragging you down the most and go from there
Any suggestions on easiest way to trace that?
For example is there a way I can inspect the sql being generated by drizzle and then run in my local sql app (table plus)
Yeah, you can pass logger:true in the options to drizzle
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Awesome do you think this approach makes more sense than using something like console.time ?
No, I think console.time is better
On each query. But you still need to look at the query to see what can be optimized. With indexes and stuff like that
Thank you appreciate your advice here!
Maybe if I continue to run into issue I should delegate some of the work to background jobs, and also I could consider not awaiting the promise to resolve if non-dependant queries.
I have mostly setup indexes on everything but I believe it is probably due to running lots of dependant queries in one serverless function