How does JS achieve traversal progress display without increasing browser IDLE time?

how does JS achieve traversal progress display without increasing browser IDLE time?

is doing a pure front-end log file analysis tool. This process requires two iterations.

initially did not consider the performance problem, the direct use of for, 5w row of sample data will take about 35 seconds to complete, this efficiency is quite worrying. (although it turns out that the performance is extremely poor when you turn on the Chrome debugging tool Performance, which is about 9 seconds if not open.)
generally starts with 30w rows of data (now the Chrome that is loaded directly into 30w rows of logs is dead).

consider adding at least one real-time progress, but you can"t render it in real time with for traversal. Look at the practice on the Internet is to rewrite it into setTimeout to do its own callback. That"s probably what it feels like:

before:

let result = [];
for (let i = 0; i < data.length; iPP) {
    //
    //result.push()
}

after:

let i = 0;
let result = []
let doThing = function(i, data, result) {
    //
    //
    //result.push()
    iPP;
    if (i < data.length) {
        setTimeout(function() {
            generateRawData(i, data, result);
        }, 0);
    } else {
        //
    }
};
generateRawData(0, data, result);
The

function is implemented, but it is found that the speed is very slow (I haven"t written the rendering code yet, so it"s certainly not the problem of slow front-end rendering). I opened the Chrome debugging tool Performance, and found that most of the time is IDLE, that is, the browser is idle, which is no good.

figure 1, Performance diagram traversed with for:

2 setTimeout Performance :

how does JS achieve traversal progress display without increasing browser IDLE time? It seems that the rendering method of setTimeout seems to be a traditional method, is there any new API that can achieve similar things?


setTimeout has a minimum interval http://rogerfederer.iteye.com.
the time it takes you to run a piece of data is much less than this interval, which results in browsers spending most of their time in IDLE

.

so, you can run hundreds / thousands more at a time and then setTimeout
or check that the running time exceeds the minimum interval of setTimeout (e.g. 10-15 ms)
and then run setTimeout for the next cycle

webworker should be a better choice


Why use settimeout? I feel that this requirement is not suitable for settimeout or setinterval

.

you can use RAF or RID, or just use webworker.


are you in a group (1000? ) rendering, in which you pause 100ms with settimeout, to let cpu and memory catch your breath.


webworker requestidlecallback?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eac3cb-20c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eac3cb-20c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?