Skip to content
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

Lag spike when adding many droppables #73

Open
zzzachzzz opened this issue Jan 13, 2023 · 2 comments
Open

Lag spike when adding many droppables #73

zzzachzzz opened this issue Jan 13, 2023 · 2 comments

Comments

@zzzachzzz
Copy link

zzzachzzz commented Jan 13, 2023

I have a scenario where upon beginning a drag operation, several new drop targets containing createDroppable are created and rendered. What I'm building is a drag and drop grid, where each cell in the grid is a drop target. Upon beginning a drag, the grid size grows +1 in rows and columns. So a 10x10 grid would grow to 11x11, resulting in 21 new cells (drop targets) being rendered.

Lag starts to get more noticeable at around a 21x21 growing to 22x22 (43 new cells / drop targets). For clarity, the lag is specifically noticeable for the item being dragged, it takes a sec to catch up only at the beginning of the drag when the new droppable cells are created. I should also note that I have skipTransform: true for all my draggables & droppables. The "transform" that I do is simply moving an item to a new cell on drag over.

I'm not very good at using the Chrome performance profiler, but from what I could gather, it seems that the lag is coming from the repeated recomputeLayouts calls, which I believe is happening for every new droppable cell.

Is there anything I can do about this? Am I going about this the wrong way?

Call Tree:
performance-profile

Bottom-Up:
performance-profile-bottom-up

@martinpengellyphillips
Copy link
Contributor

If a drag is active whilst adding droppables then recomputeLayouts is called each time for every existing droppable (as you suspected). This is because solid-dnd needs to know whether that change caused any layout shift. You can see that here:

recomputeLayouts();

I imagine that would be the cause of the lag for you. If you can share a reproducible example (e.g. codesandbox) then I can look at ways to optimise this use case (e.g. it might be an option to let you control when to recompute layouts, or we might be able to use an intersection observer for increased performance).

Aside: skipTransform likely has little impact here - that is more about controlling whether to auto set the transform when using the "directive" form.

zzzachzzz added a commit to zzzachzzz/solid-dnd_repro-issue-73 that referenced this issue Jan 16, 2023
@zzzachzzz
Copy link
Author

Thank you for your attention to this. Here's the repro example:
CodeSandbox: https://codesandbox.io/s/github/zzzachzzz/solid-dnd_repro-issue-73
GitHub repo: https://github.com/zzzachzzz/solid-dnd_repro-issue-73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants