Skip to content

Filter waiting queue tasks in place - #7537

Merged
6543 merged 7 commits into
woodpecker-ci:mainfrom
AhmadNajiKam:perf/queue-filter-waiting-in-place
Nov 11, 2026
Merged

6543 merged 7 commits into
woodpecker-ci:mainfrom
AhmadNajiKam:perf/queue-filter-waiting-in-place

Conversation

@AhmadNajiKam

Copy link
Copy Markdown
Contributor

PR description:
On every 100 ms scheduling tick, filterWaiting moved all tasks that were waiting on dependencies back into pending, created a new waiting list and filtered everything again. With many queued tasks that have dependencies, this cost almost a millisecond and ~20k allocations per tick while holding the queue lock.

This PR checks tasks where they are and only moves the ones whose state changes:

  • pending tasks that are still blocked move to the waiting list, in front of the tasks that were already waiting
  • waiting tasks whose dependencies have cleared move to the end of pending
  • all other tasks stay where they are, and the function returns early when no queued task has dependencies

The resulting order of both lists is exactly the same as before, so scheduling behaviour does not change.

Benchmarks

BenchmarkFilterWaiting, 10k tasks, benchstat over 6 runs:

Shape Time Memory Allocations
chain 929 → 318 µs (−66%) 1.67 MB → 427 KB 20,048 → 34
running-fanout 890 → 349 µs (−61%) 1.67 MB → 427 KB 20,050 → 34
mixed 550 → 299 µs (−46%) 1.05 MB → 427 KB 10,048 → 34
independent no significant change 48 B → 0 1 → 0

Smaller queue sizes improve by a similar amount. The remaining allocations are the lookup map of queued task IDs.

Tests

  • more ordering cases in TestFifoFilterWaiting
  • TestFifoFilterWaitingKeepsUnchangedTasksInPlace checks that unchanged tasks are not moved
  • TestFifoFilterWaitingMatchesRequeueAll compares the result with the previous algorithm on 500 random queues

filterWaiting moved every waiting task back to pending and rebuilt the
waiting list on each 100ms tick. Only move tasks whose state changes,
keeping the same resulting order. This cuts time by 46-66% and almost
all allocations for queues with dependencies.
@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

lint fails ...

@6543 6543 added server optimization improving runtime, memory, CPU, or I/O efficiency enhancement improve existing features labels Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.47%. Comparing base (1a84557) to head (444c22a).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7537      +/-   ##
==========================================
+ Coverage   66.40%   66.47%   +0.07%     
==========================================
  Files         449      449              
  Lines       22478    22507      +29     
==========================================
+ Hits        14926    14962      +36     
+ Misses       7552     7545       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread server/queue/fifo_test.go Resolved
@6543

6543 commented Nov 11, 2026

Copy link
Copy Markdown
Member

independent no significant change

well from 36 µs to 54 µs (+51%) is still an increase ... i brought it down to 40 µs agian

@6543
6543 merged commit 5161bd5 into woodpecker-ci:main Nov 11, 2026
9 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Nov 11, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features optimization improving runtime, memory, CPU, or I/O efficiency server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants