I used this answer to make a table with datatables.net and dc.js. However, I detected a performance issue in this loop:
function RefreshTable() {
dc.events.trigger(function () {
datatable.api()
.clear()
.rows.add( YearDimension.top(Infinity) )
.draw() ;
});
}
count = dc.chartRegistry.list().length
for (var i=count; i--;) {
dc.chartRegistry.list()[i].on("filtered", RefreshTable);
}
RefreshTable() ;
Because when resetting all the filters with
dc.filterAll();dc.redrawAll();
RefreshTable()
is executed once for every dc
chart (or dimension?). In my case it's 5 loops at ~500ms each, thus more than 2s for 4 charts and 10k records.
Has someone any idea on how to make it faster? The table should be refreshed only once.
-
\$\begingroup\$ Why is this not allowed ? >2 seconds is more a bug than a performance issue to me. And this could be usefull to others. \$\endgroup\$user456789123– user4567891232015年03月09日 20:25:20 +00:00Commented Mar 9, 2015 at 20:25
-
1\$\begingroup\$ I think this is a problem with the way the question was phrased. It turns out to be a question about the API but indeed the title makes it look like a code review question. \$\endgroup\$Gordon– Gordon2015年03月10日 12:30:04 +00:00Commented Mar 10, 2015 at 12:30
-
\$\begingroup\$ Okay I read this wrong. Indeed it is a code review question. \$\endgroup\$Gordon– Gordon2015年03月10日 21:37:19 +00:00Commented Mar 10, 2015 at 21:37
1 Answer 1
What is ineficient here is always running RefreshTable 5 times. Even if no filters where applied to any charts.
Make a new function that only resets filters from charts that have a filter.
function filterAll_performance(){
var chartlist=[chart_year, chart_genre, chart_runtime, chart_globalscore]
count=chartlist.length;
for (var i=count; i--;) {
if(chartlist[i].filters()!=0) {
chartlist[i].filterAll();
}
}
}
and replace
dc.filterAll();
with
filterAll_performance();
This will still refresh the datatable more than once sometimes but it's still better.
-
\$\begingroup\$ Congratulations, a very rare piece of well-written selfie answer :-) \$\endgroup\$janos– janos2015年09月18日 16:09:19 +00:00Commented Sep 18, 2015 at 16:09
Explore related questions
See similar questions with these tags.