RPC call slower via supabase client than via sql editor in the browser
I am working with supabase in an expo project and noticing that an RPC call that takes like 13ms in the sql editor in the supabase console can take 500ms+ via the supabase client.
I am trying to understand where the latency is coming from — is this an unavoidable overhead from the client itself (serialization etc)? Are there any strategies for paring this down?
3 Replies
How are you measuring the two times?
There should be latency involved with both for the network trips which can be 100msec or more.
Are you using impersonation when you call your function in SQL? If you have RLS on tables your functions use that would not be reflected if you run as the default postgres role.
I see, I wasn’t using impersonation but will try that. I expect the network latency but sometimes the rpc call could take like even 1000ms so I was just assuming there was something else happening.
If a chunk of latency is coming from RLS is there any workaround there other than removing policies?
There is a tuning section in the RLS documentation (under database). It can make a huge difference on select on large tables.