Async Plugin is now live: http://plugins.jquery.com/project/async
Thanks for all the feedback. I finally implemented bulk using Godmar Back's idea of a running time instead of a number of loops. With a default value of 500ms, it allows to run very small loops without any setTimeout calls and keeps browser responsiveness for long loops. Which means that you can now use an asynchronous loop on a loop that may take long but is not because you don't have enough data yet. The 500ms limit will allow the loop to run synchronously as long as it is small enough to not block the browser responsiveness, beyond the 500ms limit, the loop will start asynchronous calls by batch of 500ms each. I also added a while loop for other purposes than looping on nodes. For example, I successfully replaced the while loop in the jQuery test framework with an asynchronous one keeping browser responsiness during a full unit test session. As always, I would appreciate any feedback for this RC before releasing the final 1.0 version :) On Jul 9, 7:29 pm, "Godmar Back" <[EMAIL PROTECTED]> wrote: > BTW, thinking about this some more: > > The approach of splitting the work into N chunks of equal size, then > somehow trying to yield the CPU between each chunk, has the obvious > problems that it will > > - either lead to too many setTimeout calls, which then decrease CPU > utilization if browsers delay the execution of setTimeout(, 0) > handlers or, like Opera, don't allow them. (A poster on John's blog > pointed out that some JS runtimes even detect setTimeout(, 0) and add > delay purposefully to avoid hogging the CPU, even though this is > intended.) > > - or they lead to too few setTimeout calls, leading to browser blocking. > > Since you can't know how much each work item in a chunk takes - since > it's a user-defined function, the only solution is to tune and poll > within your work loop; if you've spent more than x milliseconds in it, > schedule a setTimeout. > > I did an experiment to that end in Firefox 2 on OSX, which is > here:http://gback.cs.vt.edu/~gback/cpuloop/tunetimer.html > It shows these results: > > for chunk max time 5000ms I finished 6108 work items before time > expired while resetting a 0ms timeout 1 times. > for chunk max time 5ms I finished 1909 work items before time expired > while resetting a 0ms timeout 326 times. > for chunk max time 7ms I finished 2390 work items before time expired > while resetting a 0ms timeout 285 times. > for chunk max time 10ms I finished 2690 work items before time expired > while resetting a 0ms timeout 228 times. > for chunk max time 15ms I finished 4087 work items before time expired > while resetting a 0ms timeout 223 times. > for chunk max time 22ms I finished 4803 work items before time expired > while resetting a 0ms timeout 176 times. > for chunk max time 33ms I finished 4731 work items before time expired > while resetting a 0ms timeout 116 times. > for chunk max time 49ms I finished 5203 work items before time expired > while resetting a 0ms timeout 85 times. > for chunk max time 73ms I finished 5513 work items before time expired > while resetting a 0ms timeout 60 times. > for chunk max time 109ms I finished 5126 work items before time > expired while resetting a 0ms timeout 38 times. > > All tests resulted in 100% CPU utilization as per "Activity Monitor." > Each test ran for 5 seconds. A work item computes the square of a > number and updates the innerHTML of a span element. > > The first test (which chunk max time 5000ms) resulted in the browser > becoming unresponsive. For the smaller max chunk sizes, the browser > retained varying degrees of responsiveness. I found it acceptable for > the 49ms and 73ms values. > > These results seem to indicate that responsiveness can be retained > while still getting 70% or 80% percent of potential CPU performance. > This test naively checks the time after every work item; there is > plenty of potential for optimization. > > - Godmar --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
