Faster single row updates
Faster single row updates
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
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:Less API calls might help.
Using
draw()
is the only way to update the Datatables data cache for searching and sorting. Maybe you don't need to usedraw()
for each update since there are 1000 per second. Maybe use a counter and use draw after every 500 updates or time period.Kevin
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. Adraw()
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 thedraw()
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
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.
Probably not by much, but something you could try and confirm.
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