DataTables 3 beta + FontAwesome performance issues

DataTables 3 beta + FontAwesome performance issues

toowtoow Posts: 1Questions: 0Answers: 0

Hi,

I'm seeing performance issues when using the DataTables 3 beta with FontAwesome JS+SVG icons.

Compared to DataTables 2, the same dataset and rendering pattern results in significantly increased rendering time (~10× slower). My table has numerous <span class="fa..."> elements being generated by render functions.

Profiling shows FontAwesome's MutationObserver callbacks increasing from ~85 samples in DataTables 2 (6.3%) to ~6195 samples (84%) in DataTables 3, with nearly all time spent in the observer callback itself.

Example using DT3beta: https://jsfiddle.net/htqrkc4y/
Same example using DT2: https://jsfiddle.net/pfowrdqx/
DT3beta "fixed" example: https://jsfiddle.net/k8myha6d/

(The performance issue is hopefully very noticeable if you try to reorder the columns, etc).

As shown in the 3rd link, Disabling Font Awesome’s mutation observer and manually calling FontAwesome.dom.i2svg() once, via the initComplete option, seems to resolve the issue, perhaps suggesting that increased DOM mutation frequency or timing differences in DT3 may be triggering excessive Font Awesome processing?

Thanks, can't begin to say how much I love DataTables and am looking forward to DT3! :smile:

Replies

  • henrik khenrik k Posts: 21Questions: 7Answers: 0

    We're also using DT and FontAwesome and recently saw warnings and errors in the console while using the libraries together. We also were using v6.x branch of Fontawesome and I decided to upgrade to v7.2+. After the upgrade to the newer version the warnings and errors disappeared.

    Perhaps worth a try

  • allanallan Posts: 65,793Questions: 1Answers: 10,945 Site admin

    Really interesting this one - many thanks for the test cases.

    What I can see happening is:

    1. In the DT3 version (with mutation observer), 7527 objects are passed into the observer callback when sorting the table, of which 1501 have a single "added" element (which is the part FontAwesome really cares about). The rest have zero.
    2. In the DT2 version, 7520 objects are passed in, of which one has 1500 added elements, one as a single element and the rest have zero.

    The upshot is that querySelectorAll in the FontAwesome code is running many individual times for the DT3 code, while for the DT2 code with jQuery it is running just once on all of the elements, and that is massively faster.

    What I need to do is group the append operations to the table body. At the moment I call Element.prototype.append() for each element, and that's what I believe is causing the issue.

    I will look into using a document fragment and then appending that. Unfortunately, I need to dash out just now, but I'll look into this further tomorrow and report back.

    Allan

  • allanallan Posts: 65,793Questions: 1Answers: 10,945 Site admin

    I made a couple of commits last night and your example is running much better with FA now: https://jsfiddle.net/0vpqd485/ .

    Those changes will be in v3.0.0 which it ships (a couple of weeks).

    Many thanks for the feedback!

    Allan

Sign In or Register to comment.