Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(quic): optimization#588

Merged
Berrysoft merged 3 commits into
compio-rs:masterfrom
Berrysoft:optimize-quic
Dec 21, 2025
Merged

perf(quic): optimization#588
Berrysoft merged 3 commits into
compio-rs:masterfrom
Berrysoft:optimize-quic

Conversation

@Berrysoft
Copy link
Copy Markdown
Member

Closes #587

  • Modify read* methods to use &mut impl IoBufMut instead of impl bytes::BufMut.
  • Use Vec instead of BTreeMap because we don't need to sort the chunks.
  • Use a smaller GSO segments value for performance.

@Berrysoft Berrysoft added this to the v0.18 milestone Dec 20, 2025
@Berrysoft Berrysoft self-assigned this Dec 20, 2025
@Berrysoft Berrysoft added performance Performance related (regression/optimization) package: quic Related to compio-quic labels Dec 20, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the QUIC implementation by refactoring buffer management and tuning performance parameters. The changes aim to improve efficiency through better API design and reduced overhead.

  • Modified read* methods to use &mut impl IoBufMut instead of impl bytes::BufMut for more efficient buffer handling
  • Replaced BTreeMap with Vec for chunk storage to eliminate unnecessary sorting overhead
  • Reduced GSO segments from 64 to 32 for improved network performance

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
compio-quic/src/socket.rs Reduces max GSO segments from 64 to 32 for performance tuning
compio-quic/src/recv_stream.rs Refactors read operations to use IoBufMut instead of BufMut, replaces BTreeMap with Vec for chunk storage, and updates buffer handling logic
compio-quic/benches/quic.rs Improves benchmark accuracy by moving timer start after connection establishment, adds proper connection cleanup, and clarifies server naming
Comments suppressed due to low confidence (1)

compio-quic/src/recv_stream.rs:530

  • Double advance_to call detected. The read method already calls unsafe { buf.advance_to(n) } at line 259 in poll_read, but then this AsyncRead implementation calls advance_to again at line 529. This will advance the buffer position twice, leading to incorrect buffer state and potentially skipping data or causing out-of-bounds access.
                let n = n.unwrap_or_default();
                unsafe { buf.advance_to(n) }
                n

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread compio-quic/src/recv_stream.rs Outdated
Comment thread compio-quic/src/recv_stream.rs Outdated
Comment thread compio-quic/src/recv_stream.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread compio-quic/src/recv_stream.rs Outdated
Comment thread compio-quic/src/recv_stream.rs Outdated
Comment thread compio-quic/src/recv_stream.rs Outdated
Comment thread compio-quic/benches/quic.rs
Comment thread compio-quic/src/recv_stream.rs Outdated
@AsakuraMizu AsakuraMizu changed the title feat(quic): optimization perf(quic): optimization Dec 21, 2025
Copy link
Copy Markdown
Collaborator

@AsakuraMizu AsakuraMizu left a comment

Choose a reason for hiding this comment

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

The use of IoBufMut is a bit odd, because I think it's more like a compio internal thing (I'm not sure if I'm right), and it's certainly not as general as BufMut (fewer impl).

Also, there are other APIs using stuffs from the bytes crate (read_chunks/write_chunks/write_all_chunks(&mut [Bytes])).

Finally, it introduces some unnecessary unsafe, which I don't like much.

@Berrysoft
Copy link
Copy Markdown
Member Author

The reason is simple. BufMut doesn't provide reserve method.

@Berrysoft
Copy link
Copy Markdown
Member Author

Well, actually I think it's OK to use Vec in read_to_end, because other implementations (e.g., std, or compio-io) use it.

@AsakuraMizu
Copy link
Copy Markdown
Collaborator

Well, actually I think it's OK to use Vec in read_to_end, because other implementations (e.g., std, or compio-io) use it.

I was just about to say that; I've already forgotten why I didn't design it that way back then.

@Berrysoft
Copy link
Copy Markdown
Member Author

Berrysoft commented Dec 21, 2025

Illumos CI failed unexceptedly. Might because of the action itself.

@AsakuraMizu
Copy link
Copy Markdown
Collaborator

Illumos CI failed unexceptedly. Might because of the action itself.

They suddenly changed a lot of things: vmactions/omnios-vm@v1.1.5...v1.1.6

@AsakuraMizu
Copy link
Copy Markdown
Collaborator

AsakuraMizu commented Dec 21, 2025

The cause of the performance degradation has finally been found: quinn-rs/quinn#2185

@Berrysoft
Copy link
Copy Markdown
Member Author

I think I'll purpose this IO design:

  • Remove read, read_exact, write, write_all. Users can use the methods provided by futures-util.
  • Keep read_chunk & read_chunks as-is. They are the same as quinn.
  • Modify read_to_end to accept size_limit: usize and return Vec<u8> to be as same as quinn. futures-util and compio-io also provide different read_to_end implementations.

@Berrysoft
Copy link
Copy Markdown
Member Author

Oh, maybe another poll_read_uninit method could be added just like AsyncStream.

@Berrysoft
Copy link
Copy Markdown
Member Author

I removed the API changes. Let's just solve the optimization problem.

Copy link
Copy Markdown
Member

@George-Miao George-Miao left a comment

Choose a reason for hiding this comment

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

LGTM

@Berrysoft Berrysoft merged commit 848f59e into compio-rs:master Dec 21, 2025
52 of 53 checks passed
@Berrysoft Berrysoft deleted the optimize-quic branch December 21, 2025 18:00
This was referenced Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: quic Related to compio-quic performance Performance related (regression/optimization)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compio-quic severe performance regression

4 participants