Faster single row updates

Faster single row updates

amitdamitd Posts: 2Questions: 1Answers: 0
edited September 17 in DataTables 1.10

I am working on application with 1000s of rows in a table with 72 columns. The rows are updated in a frequency of more than 1000 updates per second through a web socket. The update could be for any row in the table. I need to figure out which row needs to be updated from a unique column value and update the row.

I have tried finding the row that needs update by looking at the value of unique column name index.
var filterVal = dataTable.rows().indexes().filter( function(value, index) {
return dataTable.row(value).data()[coldx] == row[colIdx];
});

Then I apply this "filterVal" to update the row using:
dataTable.row(filterVal).data(arrayData).draw();

The draw in this size of the table is taking 100ms. So, when the streams of update come from the backend, frontend is unable to handle it.

Is there a way we can "draw()" row only without drawing the whole table. Is there any faster approach to search and find row to update in the table?

Answers

  • kthorngrenkthorngren Posts: 13,816Questions: 25Answers: 3,252
    edited September 17

    Not sure it will help with the speed of the search but you can use row-selector as a function. It would look something like this:

    var rowColIdx = row[colIdx]; // so row[colIdx] doesn't need to be looked up each time
    var filterVal = dataTable.rows( function ( idx, data, node ) {
            return data[coldx] === row[colIdx] ?
                true : false;
        } )
        .indexes();
    

    Less API calls might help.

    Is there a way we can "draw()" row only without drawing the whole table. Is there any faster approach to search and find data in the table?

    Using draw() is the only way to update the Datatables data cache for searching and sorting. Maybe you don't need to use draw() for each update since there are 1000 per second. Maybe use a counter and use draw after every 500 updates or time period.

    Kevin

  • allanallan Posts: 54,714Questions: 1Answers: 8,560 Site admin

    The fastest way to select a row is via an ID. Use rowId to tell DataTables what property you have the id property in, then you can use a row selector with an ID and DataTables has a reverse map for rapid lookup.

    That doesn't help with the draw aspect though - I'd agree with Kevin's thought here. Perhaps bin them, so it happens every x updates, or once per second. A draw() will do a full filter and sort, so it does take a finite amount of time.

    A final option is to use the page option for the draw() call which means search and sort will not be updated, although this can leave the output in an "incorrect" state compared to the underlying data.

    Sounds like a cool use - is it something that is going to be publicly visible?

    Allan

  • amitdamitd Posts: 2Questions: 1Answers: 0

    Thank you for the response.

    The draw() call in intervals is also not going to work as the stream of data is continuous from the source. For the lag of around(100ms) in a second for whole table update and more than 1000 updates per second, the browser will freeze in couple of hours.

    Is the draw() going to be faster if search and sort is disabled?
    Instead of row update, if I do multiple columns update, do I still need to draw whole table?

    It's going to be internal.

  • colincolin Posts: 12,657Questions: 0Answers: 2,163

    Is the draw() going to be faster if search and sort is disabled?

    Probably not by much, but something you could try and confirm.

    Instead of row update, if I do multiple columns update, do I still need to draw whole table?

    If you update just a cell, you don't need a draw. See here when you click "update", the second row changes.

    This section of the FAQ may also help, it discusses various techniques to improve performance,

    Cheers,

    Colin

Sign In or Register to comment.