From bac27777c44a5ca9fd9f0f7d2834e0c12e30c491 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 12 Jul 2022 11:56:28 +0200 Subject: [PATCH] Perf-gain: memoize the sequence editor panel's dims to avoid unnecessary re-renders --- theatre/studio/src/panels/BasePanel/BasePanel.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/theatre/studio/src/panels/BasePanel/BasePanel.tsx b/theatre/studio/src/panels/BasePanel/BasePanel.tsx index 6a69980..cd6852a 100644 --- a/theatre/studio/src/panels/BasePanel/BasePanel.tsx +++ b/theatre/studio/src/panels/BasePanel/BasePanel.tsx @@ -1,4 +1,4 @@ -import {val} from '@theatre/dataverse' +import {prism, val} from '@theatre/dataverse' import {usePrism} from '@theatre/react' import type {UIPanelId} from '@theatre/shared/utils/ids' import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types' @@ -108,13 +108,20 @@ const BasePanel: React.FC<{ const width = Math.max(right - left, minDims.width) const height = Math.max(bottom - top, minDims.height) - const stuff: PanelStuff = { - dims: { + // memo-ing dims so its ref can be used as a cache key + const dims = prism.memo( + 'dims', + () => ({ width, left, top, height, - }, + }), + [width, left, top, height], + ) + + const stuff: PanelStuff = { + dims: dims, panelId, minDims, boundsHighlighted,