salesforce / design-system-react

Salesforce Lightning Design System for React
https://design-system-react-site.herokuapp.com/
BSD 3-Clause "New" or "Revised" License
921 stars 419 forks source link

Improve DataTable re-rendering performance #2993

Closed alexzherdev closed 2 years ago

alexzherdev commented 2 years ago

Additional description

This improves re-rendering performance of the DataTable in scenarios involving many rows (in the hundreds/thousands). Main optimizations introduced:

Note that to take advantage of these improvements, the consumer application needs to memoize the columns passed into the table:

const columns = useMemo(() => [
  <DataTableColumn key="0" />,
  <DataTableColumn key="1" />
], []);

<DataTable>{columns}</DataTable>

Traces below are from a consumer application showing reduced re-rendering when clicking a row (these are taken from the re-render caused by the focus change in the table). Overall rendering time (measured via Chrome's profiler) decreased by 40-50%.

Before

Screen Shot 2022-01-27 at 5 57 22 PM

After

Screen Shot 2022-01-27 at 6 00 24 PM

CONTRIBUTOR checklist (do not remove)

Please complete for every pull request

REVIEWER checklist (do not remove)

interactivellama commented 2 years ago

I can see a noticeable difference on a table of 250 rows (7 columns) when selecting a row! 🎉

interactivellama commented 2 years ago

@alexzherdev Please merge when ready.