-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useContext seems unexpectedly slow (with just about ~100 useContext calls) #1821
Comments
This could also be an issue with solid-start / FileRouting, maybe the long lookup chain is caused by the leaf component cell and the Context Provider sitting in different folders in the file-route-tree. |
There has been some talk about how to get the lookup to be faster. This isn't something I've experienced myself, but now that I have a reproduction I can take a look. There are a few ideas how we can significantly make an improvement here. |
@ryansolid if you want a more controlled repro you can just call useContext in a loop inside a bunch of memos. The more memos you add the slower each lookup will be, while it should really be constant. |
I know you already have a solution for this. That is what people were talking to me about. Cloning downwards instead of looking upwards. But if I understand correctly you found a happy middle ground? |
@ryansolid What I'm doing is the following:
Lookups are basically the fastest they can be, and memory usage is basically as low as it can be for every owner except context owners, creating a context owner takes a slight hit once because the parent context has to be cloned. |
Thanks @fabiospampinato for the suggestions. 1-3 were straightforward. 4 was fine for all current APIs but I had to do some hacky garbage to support the now deprecated |
Describe the bug
I feel like I have a rather average use case, a home page with ~50 cells of content, each making calls to the shared
AppContext
usinguseContext
.Now a full reload on my M1 Mac takes ~90-120ms on an M1 Macbook, on a Samsung Phone about 6-10x that long.
At this point using react-router to re-render pages on the client feels sluggish to mobile users.
Now, when looking at the Performance in chrome, I can see that:
localhost:3000 full homepage reload, 124ms, of which 18.9% (25.9ms) is the
lookup
.Deployed prod site , 92ms total, of which 9% ~ 9ms is 'le' which looks like the
lookup
.The lookup function is this one
when I open it in chrome-sources on
dev
it said the code spent 42ms just in this function.Screenshot from chrome performance analysis:
Generally speaking, if I remove the content cells, the lookup bottleneck goes way.
The complete nested structure of our site is (Abbreviated):
even a single cell instead of 4 cells stil spends 5% of it's render time in an infinite lookup loop.
The complete nesting structure of our app would be:
and
Even a single cell instead of 4 cells stil spends 5% of it's render time i a very long stack trace about
useContext
Total number of
useContext
calls was about 150, 100 to the AppContext, 50 to the AuthContext.Your Example Website or App
https://app.letsrecast.ai/
Steps to Reproduce the Bug or Issue
Expected behavior
Reloading a few cells in solid.js shouldn't take that long on modern hardware
Screenshots or Videos
Platform
solid-start - 0.2.27
solid-js - 1.7.8
@suid/base - 0.8.2
Additional context
No response
The text was updated successfully, but these errors were encountered: