krausest/js-framework-benchmark

Faster clear by running `.textContent = ""` after a rAF

adamhaile opened this issue · 2 comments

Discovered this one from vidom's fast "clear rows" result and thought I'd pass it on.

If you run .textContent = "" after a requestAnimantionFrame, it saves 35-40ms in the "clear rows" benchmark.

So tweaked vanillajs-keyed Main.clear() looks like:

    clear() {
        startMeasure("clear");
        this.store.clear();
        this.rows = [];
        this.data = [];
        var that = this;
        requestAnimationFrame(function () {
            that.removeAllRows();
            this.unselect();
        });
        stopMeasure();
    }

Same trick saves about 5ms in the "replace all rows" test.

Thanks - very interesting. I implemented it only for clear all rows where it improved the benchmark significantly.
As for replace all rows I decided not to implement it, since I've seen the 5 mecs improvement you described but about half of the time it performed worse (maybe a case of bad timing when it almost had to wait almost 17 msecs for the next frame).

Updates results here