Repository navigation
Description
Bug report
- [ x ] I confirm this is a bug with Supabase, not with my own application.
- [ x ] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
supabase.auth.getSession() can take anywhere from 20ms up to 100ms on a fast processor (M2 Pro) when invoked e.g. during an initial page rendering phase. This feels way too slow for a function that doesn't do any network calls.
For comparison, a custom function I mocked up that reads the cookie, parses accessToken and returns the JWT as an object (json.parse+base64decode+json.parse) takes around 0.3-0.4ms under the same load, and is similarly performant during idle and rendering phase.
Benchmarks (rough):
During rendering phase:
- Custom JWT decode: <0.4ms
- await supabase.auth.getSession(): ~50ms
Idle phase:
- Custom JWT decode: <0.4ms (very stable and predictable)
- await supabase.auth.getSession(): 0.8-1.7ms (significantly better, but all over the place even during an idle phase)
Given the above, it's unlikely that it's caused by anything specific to my app, since the custom implementation doesn't slow down at all during rendering phase vs. idle phase.
To Reproduce
- Run the below code e.g. when rendering a React component
console.time("getSession");
const { data, error } = await supabase.auth.getSession();
console.timeEnd("getSession");- Refresh the page
Expected behavior
Under 1ms performance for a function that is doing simple local processing..
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: macOS
- Browser (if applies) Chrome
- Version of supabase-js: latest
- Version of Node.js: 20
Additional context
What's worse, it's similarly slow even when there's no cookie present.
Activity
lauri865 commentedon Feb 8, 2024
Just checked the implementation - could it be due to the locking mechanism? It's a bit unclear (to an outsider) why the function as a whole needs locks? Refresh session, sure, perhaps not the session fetching part.
I imagine it's often used for client-side route protections, etc. Which just adds an unnecessary delay to page renders and delay before data fetching starts.
MatthewDlr commentedon Apr 27, 2024
Just noticed the same thing here!
Meanwhile this is fixed, can you share your JWT implementation pls ?
Thx
Ruthenz commentedon Jul 9, 2025
Hey! would love to know if anyone saw this?
I see for me it also takes 100ms minimum which seems really long for checking a JWT.
lauri865 commentedon Aug 18, 2025
We use this code snippet, takes ~0.2ms on my machine, supports chunked cookies as well or any other storage adapter you may use:
github-actions commentedon Feb 15, 2026
This issue has been automatically marked as stale because it has not had any activity for 6 months.
It will be closed in 30 days if no further activity occurs.
If this is still relevant, please comment to keep it open.
Vickyfreshmusik commentedon Feb 15, 2026
karan-963 commentedon Aug 17, 2026
Hey everyone! 👋
I've opened a PR addressing this: #2618.
Root Cause & Solution
During initial page rendering and multi-component mounts (React / Next.js), calling
getSession()in parallel caused calls to queue sequentially behind mutual-exclusion locks (_acquireLock) and redundant async storage reads (getItemAsync), compounding latency to 20ms–450ms+.The PR introduces:
getSession()no longer blocks in mutual-exclusion lock queues.deepClone).🌐 Live Browser Test Harness
You can test the fix live in your browser on your own hardware here:
👉 https://karan-963.github.io/supabase-js/
Would love for you to test this branch with your setups and share feedback!
mandarini commentedon Oct 16, 2026
Hi @lauri865, thank you for opening this issue! 💚
Closing as fixed. The cause was the
navigator.locksmutex and queue aroundgetSession(), removed as the default in v2.107.0 (#2392). It is now a storage read plus expiry check, no lock. Passing a customlockopts back into the old path.If you still see this on 2.107.0 or later, open a new issue with the version and timings.