First request takes 8 seconds (cold start)
A practical fix and a copyable AI coding prompt. Replace bracketed placeholders with your project details.
1. Check the problem
Move heavy initialization into module scope so it caches across warm invocations. On Postgres, use a connection pooler like PgBouncer, direct connections cold-start slow. Trim dependencies too, bigger functions cold-start slower.
2. Use the prompt
My first request is slow because of a cold start. Stack: [Vercel functions / Supabase Postgres]. Help me move heavy initialization to module scope so it caches across warm invocations, add a connection pooler for the database, and trim function size. Show me the specific code to move.3. Verify the fix
Review the proposed diff, run the relevant checks and exercise the original failing flow before merging.
Continue in the related workflow chapter.