I would do a batch processing..
for instance if you have 10.000 calls to the same function (or different
functions) split it into groups of 100 calls that happens on a setTimeout...
it will take longer to process everything but it won't lock the UI..
something like:
--
var N_ITEMS_PER_BATCH = 100;
var totalItems = 10000;
var count = 0;
function batchProcess(){
var mod = (totalItems - count) % N_ITEMS_PER_BATCH;
var n = mod? mod : N_ITEMS_PER_BATCH;
//will lock UI until loop finishes
for(var i=0; i < n; i++){
doSomething(i + count); //process your stuff here
}
count += n;
updateProgress(totalItems / count); //here is where you should update the
progress
if(count < totalItems){
setTimeout(batchProcess, 15); //will free thread for updates during
~15ms
}
}
batchProcess();
--
sometimes perceived performance is more important than actual speed,
feedback changes a lot the user perception of slowness...
PS: naive implementation just for explanation purposes, could be easily
abstracted into something more generic that would work for multiple cases.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]