Skip to content

perf(storage): implement fast-path for queue delivery in _StreamMultiplexer#16718

Open
zhixiangli wants to merge 1 commit intogoogleapis:mainfrom
zhixiangli:zhixiangli/fast-path-queue-put
Open

perf(storage): implement fast-path for queue delivery in _StreamMultiplexer#16718
zhixiangli wants to merge 1 commit intogoogleapis:mainfrom
zhixiangli:zhixiangli/fast-path-queue-put

Conversation

@zhixiangli
Copy link
Copy Markdown
Contributor

@zhixiangli zhixiangli commented Apr 20, 2026

Summary

This PR optimizes the message delivery logic in _StreamMultiplexer to reduce latency and event loop overhead.

Performance Improvements:

  1. Fast-path Delivery: Implemented a "fast-path" that attempts queue.put_nowait(item) for all target queues. For queues with available capacity, this is a synchronous operation that avoids:
    • Creating and scheduling a coroutine.
    • Yielding to the event loop.
    • Overhead associated with asyncio.wait_for.
  2. Single-Queue Slow-path Optimization: In cases where exactly one queue is full, the multiplexer now directly awaits the _put_with_timeout coroutine. This bypasses the overhead of asyncio.gather, which is now only used when multiple queues are full simultaneously.
  3. Reduced Event Loop Pressure: By minimizing the number of tasks created and yields performed during high-throughput streaming, these changes help the multiplexer keep up with fast-arriving gRPC responses.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the delivery of items to multiple queues in the _stream_multiplexer.py module. It introduces a new _put_to_queues method that implements a fast path using put_nowait for available queues and a slow path with a timeout for full queues, reducing unnecessary overhead from asyncio.gather and coroutine yields when queues have capacity. The _recv_loop has been refactored to use this optimized delivery mechanism. I have no feedback to provide as there were no review comments to evaluate.

@zhixiangli zhixiangli marked this pull request as ready for review April 20, 2026 09:42
@zhixiangli zhixiangli requested a review from a team as a code owner April 20, 2026 09:42
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