-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up when events spawn events #3
Comments
Thank you for your input, I am also working on another way of speeding things up, so hopefully I can combine the two, and get significant speedup. I am currently trying to isolate the slow parts in my other attempt at speedup, in order to prove if it's even worth doing. I'll leave this ticket open for further discussion until there's a conclusion to the investigation. |
As far as I can tell from the code example, it just breaks the execution chain for the first message, after that it's still using synchronous delivery, which kind of defeats the point of async delivery. I am closing this, please reopen if I've completely misunderstood the example |
Perhaps I am misunderstanding what you mean by asyncronous delivery. I interpreted it as not "blocking" the execution of the caller of publishAsync. To this end, this is a fast implementation because it avoids the overhead of setTimeout as much as possible. You may be worried because the event pump calls publishSync. I believe I just extracted the common code from the asynchronous and synchronous version, and it happened to be the entire synchronous version. But the "event queue" guarantees the same ordering as calling setTimeout for every publishAsync. But, if you mean by asynchronous that it doesn't block the graphics/Ajax processing then you have a few options. You could discard this code and stay with the costly setTimeout per publishAsync. Or you could add a limit to the processing done within the event pump; i.e. after n messages or m milliseconds, reschedule the event pump (setTimeout) to take care of the rest of the work later. |
For the sake of completeness, I've fixed the broken last version on jsPerf: |
There's a simple way to increase the throughput of asynchronous events when they spawn each other.
The idea is to only have the first call to publish() call setTimeout, which creates an event pump for all the events that the first event spawned. These subsequent events get added to a queue, which the event pump drains. When the event queue is empty, the pump exits (returns in javascript), and the next event spawns a new event pump.
I've coded it up:
jsperf (unpublished): http://jsperf.com/pubsubjs-vs-jquery-custom-events/17
code: https://gist.github.com/1715452
(I also cleaned up the code a bit, but didn't have access to all the tests, which is why I didn't do this as a pull request.)
The text was updated successfully, but these errors were encountered: