Skip to content

[Performance]: Avoid full priority-queue scans for bounded admission peeks #21912

Open

Description

@Hang-get

Proposal to improve performance

PriorityWaitingQueue.peek_requests(k) currently uses heapq.nsmallest, which scans every queued request and maintains a size-k heap. With priority scheduling and KV-balanced attention-DP admission enabled, this runs every admitting scheduler iteration; the configured admission window is normally 32 requests.

For a bounded peek, the queue's existing heap structure can enumerate the next requests through a best-first frontier. This visits only the relevant heap branches, reducing the work from O(n log k) to O(k log k) without copying, sorting, or mutating the full queue. Large result sets can retain the existing nsmallest path.

I have a focused patch and CPU-only equivalence tests ready.

Report of performance regression

Benchmark on current main (a545268cf3e6), using the real PriorityWaitingQueue implementation with identical randomized priority heaps. Each process used 5 warmups and 31 timed calls; the table reports the median of five process medians.

Queued requests Peek size heapq.nsmallest Bounded frontier Speedup
2,048 32 0.093 ms 0.021 ms 4.4x
8,192 32 0.349 ms 0.022 ms 15.9x
8,192 64 0.367 ms 0.046 ms 8.0x
8,192 256 0.534 ms 0.214 ms 2.5x
8,192 2,048 2.377 ms 2.373 ms unchanged

At the default 32-request KV-balance window, an 8,192-request waiting queue saves about 0.33 ms per admitting iteration.

Misc discussion on performance

The output order is identical to repeated priority-queue pops, and the source heap remains unchanged. I found no open pull request touching this function and no open or closed issue covering this overhead.

Your current environment

  • OS: Linux x86_64
  • CPU: Intel Xeon Platinum 8352Y
  • Python: 3.11.18
  • GPU/CUDA: not used
  • TensorRT-LLM: main at a545268cf3e6

Before submitting a new issue...

  • I searched relevant open and closed issues and pull requests.

Activity

  1. added
    General perf<NV>Broad performance issues not specific to a particular component
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    General perf<NV>Broad performance issues not specific to a particular component

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions