1
\$\begingroup\$

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.

asked Mar 9, 2015 at 19:12
\$\endgroup\$
3
  • \$\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\$ Commented 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\$ Commented Mar 10, 2015 at 12:30
  • \$\begingroup\$ Okay I read this wrong. Indeed it is a code review question. \$\endgroup\$ Commented Mar 10, 2015 at 21:37

1 Answer 1

1
\$\begingroup\$

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.

answered Mar 10, 2015 at 13:09
\$\endgroup\$
1
  • \$\begingroup\$ Congratulations, a very rare piece of well-written selfie answer :-) \$\endgroup\$ Commented Sep 18, 2015 at 16:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.