Responsive plugin performance tweak

Responsive plugin performance tweak

DanSwitzer2DanSwitzer2 Posts: 21Questions: 4Answers: 0

I've noticed what I think is a very minor tweak to the Responsive plugin, that has a nice performance boost.

The column-sizing event ends up being bound during the preInit event. For my table configuration, that ends up triggering the column-sizing event 3 times during the initialization process.

I've added a console.time()/timeEnd() to dump out those execution times and I see this in my console:

Responsive-column-sizing: 49.08ms
Responsive-column-sizing: 38.06ms
Responsive-column-sizing: 13.5ms

If I move the code to bind in the dt.on( 'init.dtr' ) event instead (so it waits until after initializing to bind the resizing behavior), it ends up saving over 100ms on initialization time. The init.dtr event already calls that._resizeAuto() and that._resize().

It would appear there's no reason that the column-sizing.dtr event would need to be fired until after the plugin has fully initialized.

I don't think this breaks anything (but I could be missing something), but it can end up saving a lot of CPU cycles—especially if there are a number of instances of DataTables on the page.

Replies

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Excellent suggestion - thanks for this! I'll get that added in and post back here when done.

    Allan

  • DanSwitzer2DanSwitzer2 Posts: 21Questions: 4Answers: 0
    edited January 2018

    I suspect there are several other events that could be delayed on being wired up until the init event (column-visibility, draw.dtr, column-reorder.dtr) because they might lead to excessive calls during the initialization process.

This discussion has been closed.