Skip to content

Commit 4a835b8

Browse files
committed
Factor out rendering of table body to a memoized component
1 parent ab00152 commit 4a835b8

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

extensions/ql-vscode/src/view/compare-performance/ComparePerformance.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ChangeEvent } from "react";
2-
import { Fragment, useMemo, useRef, useState } from "react";
2+
import { Fragment, memo, useMemo, useRef, useState } from "react";
33
import type {
44
SetPerformanceComparisonQueries,
55
ToComparePerformanceViewMessage,
@@ -577,15 +577,12 @@ function ComparePerformanceWithData(props: {
577577
</HeaderTR>
578578
</thead>
579579
</Table>
580-
{rowGroups.map((rowGroup, rowGroupIndex) => (
581-
<PredicateRowGroup
582-
key={rowGroupIndex}
583-
renderedName={rowGroupNames[rowGroupIndex]}
584-
rowGroup={rowGroup}
585-
comparison={comparison}
586-
metric={metric}
587-
/>
588-
))}
580+
<PredicateTable
581+
rowGroups={rowGroups}
582+
rowGroupNames={rowGroupNames}
583+
comparison={comparison}
584+
metric={metric}
585+
/>
589586
<Table>
590587
<tfoot>
591588
<tr key="spacing">
@@ -606,6 +603,28 @@ function ComparePerformanceWithData(props: {
606603
);
607604
}
608605

606+
interface PredicateTableProps {
607+
rowGroups: RowGroup[];
608+
rowGroupNames: React.ReactNode[];
609+
comparison: boolean;
610+
metric: Metric;
611+
}
612+
613+
function PredicateTableRaw(props: PredicateTableProps) {
614+
const { comparison, metric, rowGroupNames, rowGroups } = props;
615+
return rowGroups.map((rowGroup, rowGroupIndex) => (
616+
<PredicateRowGroup
617+
key={rowGroupIndex}
618+
renderedName={rowGroupNames[rowGroupIndex]}
619+
rowGroup={rowGroup}
620+
comparison={comparison}
621+
metric={metric}
622+
/>
623+
));
624+
}
625+
626+
const PredicateTable = memo(PredicateTableRaw);
627+
609628
interface PredicateRowGroupProps {
610629
renderedName: React.ReactNode;
611630
rowGroup: RowGroup;

0 commit comments

Comments
 (0)