-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
perf: Improved pointer events related performance when the sidebar is docked with a large library open #9086
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
Hey!
Interesting find, and solution! I've mocked the API for tests since we weren't testing this part of the UI behavior anyway. We'll see if it bites us in the future. I've also kept the old logic in case the -- I'll need to go through the LibraryMenu changes tomorrow, but so far, looking good 👍. |
|
Alright, so first I removed the But then I realized that in multiplayer scenarios it will rerender the That said, there are some non-intuitive things happening, such as that without the optim (technically with the optim as well) there are more rerenders when the remote client is dragging an element you don't have selected (which should bail) as opposed to editing your own selection. Unclear why, something that can be investigated later. Thus, the quest for making Library sidebar more optimized continues, I would say — but I'm glad we've made a good step toward optimizing it :). Thanks! ❤️ |
… docked with a large library open (#9086) Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
… docked with a large library open (#9086) Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
… docked with a large library open (#9086) Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
When the sidebar is docked with a sufficiently large library open, there is some perceptible lag and choppiness during canvas interaction. This PR aims to improve performance and UX in this scenario.
My first impulse + our offline discussion led me to investigate any unnecessary re-renders. Something that both
LibraryMenuandLibraryMenuContentare guilty of. By memoizing both components, I managed to mitigate this. With it, I also improved thepending elements calculation, as in the current version, rotation and resizing do not update the preview element correctly. These optimizations helped somewhat, but did not fully resolve the performance issue.My next thought was that it might be the large number of (potentially) complex SVGs in the sidebar that may be the culprit. One approach I tried was lazy loading them with
IntersectionObserver. The idea was to only insert the currently visible ones into the DOM. This showed some promise and definitely seemed to result in noticeably improved performance, but it still did not match the sidebar-less version.However, this detour helped me identify the real bottleneck. I noticed that although pointer events no longer triggered React re-renders, there was still some unusual behavior. After some more investigation, I found that the App component frequently changes the
--ui-pointerEventCSS variable to block other elements' interactivity, and applying these changes was the root cause of the lags.My proposed solution is to remove these changes while maintaining the same UX (i.e., no interaction with outside elements during canvas interaction). During a canvas pointer up event, we capture the pointer events to the canvas itself. This ensures that all other outside elements will be non-interactive until a pointer up event. I tested this solution and it provides the same UX as before, though there could be some edge cases I'm not aware of. Unfortunately, I have noticed the tests are failing because
pepjs, the library that polyfills pointer events tojsdomdoes not properly support the capturing phase for pointer events. Still, I think this idea is worth considering at least.Here is a short video comparing prod vs PR performance with the fix applied:
excalidraw.mp4