fix: bump neighbours performance regression (#7748)

* fix: move bumping neighbours to the end of rendering

* chore: remove scheduleSnapAndBump

* chore: remove references to bumpNeighbours

* chore: work on fixing tests

* fix: bump neighbours event grouping

* chore: format

* chore: readd deprecation import

* fix: move event ordering

* chore: undeprecate bumpNeighbours

* fix: bumping during drag due to insertion markers

* chore: tests

* chore: PR feedback

* chore: docs

* chore: typo
This commit is contained in:
Beka Westberg
2024-01-17 10:48:04 -08:00
parent 43f6df92a3
commit 8c5f32b2f9
10 changed files with 35 additions and 59 deletions

View File

@@ -6,6 +6,7 @@
import {BlockSvg} from './block_svg.js';
import * as userAgent from './utils/useragent.js';
import * as eventUtils from './events/utils.js';
/** The set of all blocks in need of rendering which don't have parents. */
const rootBlocks = new Set<BlockSvg>();
@@ -13,6 +14,9 @@ const rootBlocks = new Set<BlockSvg>();
/** The set of all blocks in need of rendering. */
let dirtyBlocks = new WeakSet<BlockSvg>();
/** A map from queued blocks to the event group from when they were queued. */
let eventGroups = new WeakMap<BlockSvg, string>();
/**
* The promise which resolves after the current set of renders is completed. Or
* null if there are no queued renders.
@@ -100,6 +104,7 @@ function alwaysImmediatelyRender() {
*/
function queueBlock(block: BlockSvg) {
dirtyBlocks.add(block);
eventGroups.set(block, eventUtils.getGroup());
const parent = block.getParent();
if (parent) {
queueBlock(parent);
@@ -124,9 +129,19 @@ function doRenders() {
const blockOrigin = block.getRelativeToSurfaceXY();
block.updateComponentLocations(blockOrigin);
}
for (const block of blocks) {
const oldGroup = eventUtils.getGroup();
const newGroup = eventGroups.get(block);
if (newGroup) eventUtils.setGroup(newGroup);
block.bumpNeighbours();
eventUtils.setGroup(oldGroup);
}
rootBlocks.clear();
dirtyBlocks = new Set();
dirtyBlocks = new WeakSet();
eventGroups = new WeakMap();
afterRendersPromise = null;
}