Reland [Optimize TaskQueueSelector]

The previous patch was starving low priorirty tasks more by
accident which was enough to make some layout tests "leak"
blink objects.

Previous patch: http://crrev.com/c/1397612

This patch reimplements the priority selection logic by maintaining a
priority queue of task priorities.  I.e. to select a task we first
check the current highest priority priority with tasks and then select
the oldest queue from within that priority.

To account for task starvation we keep a count of the number of times
we have selected a task, and assign each priority a sort key based on
the current task count plus a priority specific bias.  After selecting
a queue, we re-evaluate the sort key for the associated priority.

This means if we run a lot of say high priority tasks, the sort key for
any waiting normal priority will eventually become lower than the
key for the high priority, resulting in us selecting a "starving"
normal priority queue.

Despite the overhead of maintaining this new queue, it's still makes a
4% improvement on SequenceManagerPerfTest.PostImmediateTasks_OneQueue.

Bug: 897751
Change-Id: Ia7737343f1a82f190802e0da1ed16989cf10e14e
Reviewed-on: https://chromium-review.googlesource.com/c/1404091
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#621976}
10 files changed