-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Try improving ListView drag and drop performance by computing blocksData
ahead of time
#50210
Conversation
Size Change: +178 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up! I like the idea of computing the data much less frequently. One question this change potentially raises is what to do about blocks rendered as placeholders in a long list view when the drag is initially started and then a user drags up or down the list to where the windowed/placeholder rows are rendered.
Would it be worth outputting the expected data-block
, data-expanded
, etc in the placeholder row around here: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/list-view/branch.js#L199?
I tried instrumenting When you start adding a lot of blocks, there are other performance issues in the editor that cause more issues than drag and drop (Things like scrolling and even toggling the list view sidebar open is noticeably slow). |
Flaky tests detected in 7467553. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4848418920
|
Thanks for giving this one a look anyway, it was worth exploring 🙂 |
What?
Originally, when ListView drag and drop was introduced, there was a performance optimization in that the expensive
blocksData
was computed only once when the user started dragging.At some point this has regressed and the data is now computed on every trigger of the dragover event.
This PR ensures
blocksData
is only be computed on drag start.Why?
The block list doesn't change when a user is dragging, so this isn't needed.
This could be revised when collaborative editing is introduced, as then the block list may change while the user is dragging 😬. Hopefully there will be other ways to recompute the data (i.e. whenever the
blockOrder
changes?)How?
Store blocksData in a
ref
when the user starts dragging and clear it when the user stops.Testing Instructions
The easiest way to test is to set a logpoint in the
getBlocksData
function. Then start dragging and you should see only one line of console output.