Memoise selection of nodes

Summary:
For the visualiser we use the same trick as with the hover state. We subscribe to selection changes and only render if the prev or new state concerns us.

For the tree we change from object identity to the node id + and indent guide are added to the memoisation equal check.

Depending on teh change this tree memoisation can vary in effectiveness. If you go from nothing selecting to selecting the top element nothing is memoised since react needs to render every element to draw the indent guide. If you have somethign selected and select a nearby element the memoisation works well.

There are ways to improve this more down the road

changelog: UIDebugger improve performance of selecting nodes

Reviewed By: lblasa

Differential Revision: D43305979

fbshipit-source-id: 5d90e806ed7b6a8401e9968be398d4a67ed0c294
This commit is contained in:
Luke De Feo
2023-02-17 02:45:05 -08:00
committed by Facebook GitHub Bot
parent 786ae04d21
commit 8581aa1944
6 changed files with 91 additions and 47 deletions

View File

@@ -35,7 +35,6 @@ export function Component() {
const metadata: Map<MetadataId, Metadata> = useValue(instance.metadata);
const [showPerfStats, setShowPerfStats] = useState(false);
const [selectedNode, setSelectedNode] = useState<Id | undefined>(undefined);
const [visualiserWidth, setVisualiserWidth] = useState(500);
@@ -54,12 +53,7 @@ export function Component() {
<Layout.Horizontal grow pad="small" gap="small">
<Layout.Container grow gap="small">
<Layout.ScrollContainer>
<Tree2
selectedNode={selectedNode}
onSelectNode={setSelectedNode}
nodes={nodes}
rootId={rootId}
/>
<Tree2 nodes={nodes} rootId={rootId} />
</Layout.ScrollContainer>
</Layout.Container>
@@ -76,16 +70,12 @@ export function Component() {
rootId={rootId}
width={visualiserWidth}
nodes={nodes}
selectedNode={selectedNode}
onSelectNode={setSelectedNode}
onSelectNode={instance.uiActions.onSelectNode}
modifierPressed={ctrlPressed}
/>
</ResizablePanel>
<DetailSidebar width={350}>
<Inspector
metadata={metadata}
node={selectedNode ? nodes.get(selectedNode) : undefined}
/>
<Inspector metadata={metadata} nodes={nodes} />
</DetailSidebar>
</Layout.Horizontal>
</Layout.Container>