
Performance Testing Fastify App Builds & Database Connections
TLDR; One-line takeaways Supabase vs Local: ~ 57× slower per request (adds ~ 61 ms ). New DB connection each test (Supabase): ~ 6.6× slower than reusing (adds ~ 448 ms ). Build+close app each test: adds about ~19 ms per test (Supabase) and ~16–17 ms per test (local). It all started with one question: When I'm testing my Fastify app, doesn't it cost a lot of performance to build() and close() the app for every test? Especially since I am opening a sql connection every time it builds. So with the help I wrote a test (with the help of AI): describe ( " Fastify app lifecycle perf " , () => { it ( " A) build+close per test " , async () => { const t0 = nowMs (); for ( let i = 0 ; i < 10 ; i ++ ) { const app = await buildTestApp (); const res = await app . inject ({ method : " GET " , url : " /readyz " , }); expect ( res . statusCode ). toBe ( 200 ); await app . close (); } const t1 = nowMs (); console . log ( " A) build+close per test: " , ( t1 - t0 ). toFixed ( 1 ), " ms " ); expect ( true
Continue reading on Dev.to
Opens in a new tab

