question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimizing Performance with customBodyRender

See original GitHub issue

Hi,

I have a relatively simple use case. But am finding mui-datatables to be non-performant as my data set grows (up to just 100 records). I’m guessing it’s because I use a customBodyRender on each of 5 columns…and it seems that function is being run for all fields in all rows even when just one row is updated. Let me try and explain:

  1. I have an array of objects in a redux store. Each object looks like this: {inbound:false, id:-1,message: [0x90,0x3c,0x64], delta:1, timestamp: new Date() }
  2. This array is appended to (perhaps a few times per second) by a socket.io middleware–>reducer. It’s size, however, is limited to just 100 entries. state.midi.history = [newPayload].concat(state.midi.history).slice(0,ITEM_HISTORY_LIMIT);
  3. In my mui-datatable component, I subscribe to the relevant redux state in mapStateToProps. const mapStateToProps = (state, ownProps) => { return { midi: state.midi}; };
  4. …and feed it to the mui-datable: <MUIDataTable title={"Midi Messages"} data={this.props.midi.history} columns={Columns} options={options} />
  5. My mui-datatable has 5 columns - but because my source data is “raw”, 3 of them require (I think) customBodyRenders. Example:
  • timestamp. the source data is a date object. inside customBodyRender, I run the value through a helper function that returns a string.

  • message. the source data is an array of bytes. I run the array through a helper function that returns a prettified string marked up with colors.

  • translation. there is no translation field in the source object. I lookup the message byte array (see above), and run it through a helper function that returns a marked up Fragment. let msg = tableMeta.rowData[_.findIndex(Columns, { name: "message" })]; let map = MCUMap(msg); … …

     <Typography className={inbound ? "inbound" : "outbound"}>
          <span className="partHL2">{abbr}</span>
          <span>{map.target ? out : msg.toString()}</span>
     </Typography>
  );

It all works. BUT as the array of objects grows, even to just 50, the fact seems to be that the table is re-calculating every field in every row and it gets slow. I thought, in react, one could/should use a key on list/table data so that only rows with a new key got updated. Not the 99 rows that didn’t change. But that paradigm doesn’t seem to exist here.

Of course, it could just be that my approach is all wrong – and so would appreciate advice. I love the searching and filtering and general ease of use of mui-datatables – so would love to get this fixed!

Here’s a pic of the resultant table: Capture

Thanks.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
skavancommented, Mar 17, 2021

I think I gave up on mui-datatables for that app although I use it extensively for smaller (<1000) tables.

0reactions
MrRainesEcommented, Jan 24, 2022

Hi @skavan which table package do you use for data >1000?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimization Of Render Datatables - ADocLib
In this tutorial, you will learn how to maximize React performance by ... etc. of column with buttons I defined in 'customBodyRender' Expected...
Read more >
22 React Performance Optimization Techniques
22 React Performance Optimization Techniques. Best Optimization Techniques for React Programming. Optimize React with Simple Steps !!!
Read more >
datatables responsive fixed column width - Vibratissimo
Performance optimization. ... customHeadRender is called with these arguments: customBodyRender is called with these arguments: The table lends itself to ...
Read more >
MUI Datatables: Datatables for React using Material-UI - Morioh
customBodyRender, function, Function that returns a string or React component. Used to display data within all table cells of a given column.
Read more >
datatables render row index - PenaMerahPutih.com
The way those columns are accessed in customBodyRender is nasty.. meta. ... A lot of the features and performance enhancements that are now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found