kriskowal / asap

High-priority task queue for Node.js and browsers
MIT License
609 stars 45 forks source link

Microtask queue can be made faster #59

Open Pauan opened 9 years ago

Pauan commented 9 years ago

I have created a jsperf for queues. drain_Array is a naive Array.prototype.shift, drain_ArrayQueue is asap's optimization, and drain_Queue uses an implementation of Queues that has O(1) push and amortized O(1) pull.

With my machine, using Google Chrome, asap's optimization for array removal ends up being significantly slower than a naive shift! It seems likely that Chrome already optimizes shift (possibly using a similar technique that asap uses).

The Queue implementation is roughly the same speed as naive shift, but it should be consistently fast on all browsers (even those that don't optimize shift).

Of course, it is possible that I messed up in making the test, and that the results are incorrect.

kriskowal commented 9 years ago

First step would be to build a benchmark. If someone provides a PR for a bench, I can measure across all the SauceLabs configurations and get some data.

kriskowal commented 9 years ago

I am interested in simplifying ASAP based on this insight. Pull requests welcome for benchmark or simplification of the queue.

Pauan commented 9 years ago

Okay, how would I (or anybody else) go about submitting a benchmark to this repository?

kriskowal commented 9 years ago

@Pauan I am open to nearly anything. We can refine as we go.