Skip to content

[IoUringReadIter] Buffer out-of-order items - #8667

Closed
coszio wants to merge 1 commit into
devfrom
ordered-uring-iter
Closed

coszio wants to merge 1 commit into
devfrom
ordered-uring-iter

Conversation

@coszio

@coszio coszio commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer: I know I know. We want to reduce the number of allocations as much as possible. This PR introduces a bit of overhead by using a hashmap as buffer, but I don't think it is that bad because:

  • Shares the same hashmap for the iterator, so no new allocations unless we grow it.
  • Uring already allocates a vector, in this case we are moving the pointer to the hashmap (I think?).
  • Even though we are introducing hashing, the hashed type is usize, so should be quick, and IO costs a lot more anyway.

Returning things out-of-order makes handling the iterator a lot more complex (example), and makes users of UniversalRead iterator having to handle the special case of IoUring for every case.

For iterators, we almost always have to wait until the next sequential item, even if we are capable of processing others in the meantime. So I think there is no big benefit of complicating the callsites everywhere, when we can contain it to the read iterator itself.

This PR ensures items are in order by:

  • always draining the completion queue.
  • checking if the next sequential item is there.
  • saturating the submission queue with more items.

@coszio
coszio requested review from ffuugoo, generall and xzfc April 13, 2026 20:53
@coszio coszio mentioned this pull request Apr 13, 2026
@coderabbitai

coderabbitai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR introduces sequence-based ordering to handle out-of-order completions in IoUringReadIter. The iterator now wraps metadata with sequence numbers (usize, Meta), adds next_submit_seq and next_seq counters, and maintains an internal buffer for storing out-of-order read results. The completion handling logic in next_impl is restructured to enqueue reads with increasing sequence numbers, wait for completions, drain all available ones, return the matching sequence number, and buffer others. Additionally, IoUringRuntime documentation for enqueue_while is clarified and the completion_is_empty() public method is removed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • generall
  • ffuugoo
  • xzfc
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: buffering out-of-order items in IoUringReadIter to ensure sequential delivery.
Description check ✅ Passed The pull request description directly addresses the changeset by explaining the buffering mechanism, its rationale, and the order-preservation strategy implemented in the IoUringReadIter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ordered-uring-iter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coszio

coszio commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

After discussion with the team, if we were to use this, we would prefer to make it a wrapper, rather than changing the original implementation.

@coszio coszio closed this Apr 14, 2026
@generall
generall deleted the ordered-uring-iter branch May 30, 2026 21:23
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