Skip to content

perf(server): keep the pending queue sorted instead of re-sorting per dispatch (RIG-1180) - #32

Open
rigel-mintaka wants to merge 1 commit into
mainfrom
pipelines/rig-1180-sorted-insert-dispatch
Open

perf(server): keep the pending queue sorted instead of re-sorting per dispatch (RIG-1180)#32
rigel-mintaka wants to merge 1 commit into
mainfrom
pipelines/rig-1180-sorted-insert-dispatch

Conversation

@rigel-mintaka

Copy link
Copy Markdown

Replace the per-dispatch full re-sort of the pending queue with sorted-insert helpers. Previously assignToWorker called pendingByCreation() on every dispatch, copying the whole pending list and running slices.SortStableFunc to order it by taskOrderLess (creation time, then workflow name).

The sort key is immutable once a task is queued, so the order can be maintained at insertion time instead. pushPending inserts a task into its creation-order position (after equals, matching the append-then-stable-sort order it replaces); pushPendingFront places a resubmitted expired task ahead of its equals, preserving the retry priority a list push-front gave it. filterWaiting now merges the two already-sorted lists in a single walk. assignToWorker walks the pending list directly.

New tests cover multi-dispatch tick ordering, the two insert helpers' placement among equals and at the list ends, and filterWaiting drain ordering.

Co-authored-by: Matt Wilkinson matt@rigel.build

Spec-impact: none. Refs RIG-1180

@linear-code

linear-code Bot commented Aug 30, 2026

Copy link
Copy Markdown

RIG-1180

… dispatch (RIG-1180)

Replace the per-dispatch full re-sort of the pending queue with sorted-insert helpers. Previously assignToWorker called pendingByCreation() on every dispatch, copying the whole pending list and running slices.SortStableFunc to order it by taskOrderLess (creation time, then workflow name).

The sort key is immutable once a task is queued, so the order can be maintained at insertion time instead. pushPending inserts a task into its creation-order position (after equals, matching the append-then-stable-sort order it replaces); pushPendingFront places a resubmitted expired task ahead of its equals, preserving the retry priority a list push-front gave it. filterWaiting now merges the two already-sorted lists in a single walk. assignToWorker walks the pending list directly.

New tests cover multi-dispatch tick ordering, the two insert helpers' placement among equals and at the list ends, and filterWaiting drain ordering.

Co-authored-by: Matt Wilkinson <matt@rigel.build>

Spec-impact: none. Refs RIG-1180
@rigel-mintaka
rigel-mintaka force-pushed the pipelines/rig-1180-sorted-insert-dispatch branch from fc82fc4 to 90700a0 Compare August 30, 2026 16:37
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review August 30, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant