From edf3627229567683de7373ca2e35876f6685fca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20Bezen=C5=A1ek?= Date: Sat, 13 Apr 2024 21:47:16 +0200 Subject: [PATCH] Only run when shapes change. (#3456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before we were running this on any change, even mouse position changes. Now we only run it when shapes change. Results wouldn't change in any case, so there's not a huge improvement. Still, why run it if it is not necessary. Before: https://github.com/tldraw/tldraw/assets/2523721/b4111494-488a-42d0-9dfe-7fbc2ed88315 After: https://github.com/tldraw/tldraw/assets/2523721/d96de329-235b-4dcb-93ea-fe297062985d ### Change Type - [ ] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [x] `internal` — Does not affect user-facing stuff - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know --- .../editor/src/lib/editor/derivations/parentsToChildren.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/lib/editor/derivations/parentsToChildren.ts b/packages/editor/src/lib/editor/derivations/parentsToChildren.ts index 62d9d4f67..5212beea9 100644 --- a/packages/editor/src/lib/editor/derivations/parentsToChildren.ts +++ b/packages/editor/src/lib/editor/derivations/parentsToChildren.ts @@ -7,6 +7,7 @@ type Parents2Children = Record export const parentsToChildren = (store: TLStore) => { const shapeIdsQuery = store.query.ids<'shape'>('shape') + const shapeHistory = store.query.filterHistory('shape') function fromScratch() { const result: Parents2Children = {} @@ -35,7 +36,7 @@ export const parentsToChildren = (store: TLStore) => { return fromScratch() } - const diff = store.history.getDiffSince(lastComputedEpoch) + const diff = shapeHistory.getDiffSince(lastComputedEpoch) if (diff === RESET_VALUE) { return fromScratch()