Significant Performance Gap: Prisma vs Supabase Client in Nuxt 3

Issue Description I've built a performance comparison tool to test the response times between Prisma and Supabase client when querying the same Supabase database. The results show that Prisma queries are significantly slower (approximately 7-8x) than direct Supabase client queries. Environment - Nuxt 3 - Prisma - @nuxtjs/supabase - Database: PostgreSQL - Supabase - Connection: Using Supabase connection pooling (Supavisor) Code Snippet - Prisma
import prisma from '~/lib/prisma'

export default defineEventHandler(async () => {
const courses = await prisma.courses.findMany({
where: {
coursegroup: 'XXXX'
},
select: {
coursecode: true
}
})
return {
courses: courses.map(course => course.coursecode)
}
})
import prisma from '~/lib/prisma'

export default defineEventHandler(async () => {
const courses = await prisma.courses.findMany({
where: {
coursegroup: 'XXXX'
},
select: {
coursecode: true
}
})
return {
courses: courses.map(course => course.coursecode)
}
})
- SupabaseClient
import { serverSupabaseClient } from '#supabase/server'

export default defineEventHandler(async (event) => {
const client = await serverSupabaseClient(event)
const { data: courses, error } = await client
.from('Courses')
.select('coursecode')
.eq('coursegroup', 'XXXX')

return { courses }
})
import { serverSupabaseClient } from '#supabase/server'

export default defineEventHandler(async (event) => {
const client = await serverSupabaseClient(event)
const { data: courses, error } = await client
.from('Courses')
.select('coursecode')
.eq('coursegroup', 'XXXX')

return { courses }
})
Questions - Why is there such a significant performance difference between Prisma and Supabase client? - Are there any recommended configurations or optimizations for Prisma when used with Supabase? - Could this be related to connection pooling or the way Prisma establishes database connections? - Are there any best practices for improving Prisma's performance in this scenario? Additional Context - No significant load on the database - Both implementations use the same database connection string with connection pooling - The performance difference is consistent across multiple tests
No description
3 Replies
Prisma AI Help
Prisma AI Help•4w ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
overthinkerrrr
overthinkerrrrOP•4w ago
:heart: any comment is appreciate
Nurul
Nurul•3w ago
Hey 👋 Apologies for the delay in responding to this question! Currently, Prisma internally uses Rust-based query engine which handles generating SQL, running migrations, and mapping records to JavaScript/TypeScript objects. This extra translation and runtime can add overhead compared to directly using the Supabase (or raw PostgreSQL) client. (On a side note, we are working on moving this logic from Rust to TS to improve performance. More details here) Can you check if you get the same performance behaviour with a raw sql query?
const courses = await prisma.$queryRaw`
SELECT coursecode FROM "Courses" WHERE coursegroup = 'XXXX'
`;
const courses = await prisma.$queryRaw`
SELECT coursecode FROM "Courses" WHERE coursegroup = 'XXXX'
`;

Did you find this page helpful?