Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create scuffle-bytes-util #241

Merged
merged 5 commits into from
Jan 10, 2025
Merged

create scuffle-bytes-util #241

merged 5 commits into from
Jan 10, 2025

Conversation

TroyKomodo
Copy link
Member

@TroyKomodo TroyKomodo commented Jan 9, 2025

Rename bytesio to scuffle-bytes-util. We also remove the wrapper types we had and optimize the Cursor<Bytes> usage. A lot of what we did with the wrapper types was essentially what BytesMut does and what Vec<u8> does, which is why most of the usage has been replaced with that.

These changes allow for the code to have fewer copies in the rtmp implementation (I will look to further clean up the tests and code there in a future PR).

The old rtmp flow was such:

  • copy bytes from wire into a temporary buffer
  • copy that buffer into the chunk decoder (or handshake buffer) buffer
  • parse chunks/handshake
  • create a temporary buffer to write back result
  • copy result from tmp buffer onto wire.

The new flow looks like:

  • copy bytes from wire into a buffer
  • parse chunks/handshake
  • write result into a buffer
  • copy result onto the wire

The newer example reuses existing buffers; so each connection will store additional memory (roughly 10kb/connection). As apposed to creating a buffer each time we want to read or write we just reuse an existing one.

We also remove the additional copy to the handshake or chunk decode buffers by having them all share the same buffer (the read buffer).

CLOUD-23

@TroyKomodo
Copy link
Member Author

Build broken due to rust-lang/rust#135235

Comment on lines 10 to 21
/// Extracts the remaining bytes from the cursor returning.
///
/// This does not do a copy of the bytes, and is O(1) time.
///
/// This is the same as `BytesCursor::extract_bytes(self.remaining())`.
fn extract_remaining(&mut self) -> Bytes;

/// Extracts a bytes from the cursor.
///
/// This does not do a copy of the bytes, and is O(1) time.
/// Returns an error if the size is greater than the remaining bytes.
fn extract_bytes(&mut self, size: usize) -> io::Result<Bytes>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Open to naming suggestions for these methods too. I dont really like them at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

Why not read_bytes?

Copy link
Member

@lennartkloock lennartkloock left a comment

Choose a reason for hiding this comment

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

You should change the shields.io links in the readme

@TroyKomodo
Copy link
Member Author

You should change the shields.io links in the readme

which one?

Copy link
Member

@lennartkloock lennartkloock left a comment

Choose a reason for hiding this comment

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

nvm I missed the change

@TroyKomodo TroyKomodo force-pushed the troy/remove-bytesio branch from 99b1c08 to f91b832 Compare January 9, 2025 21:11
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 96.59864% with 10 lines in your changes missing coverage. Please review.

Project coverage is 50.24%. Comparing base (dc12b9a) to head (e246815).
Report is 10 commits behind head on main.

Current head e246815 differs from pull request most recent head b1a9a32

Please upload reports for the commit b1a9a32 to get more accurate results.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/rtmp/src/session/errors.rs 11.11% 8 Missing ⚠️
crates/h264/src/config.rs 66.66% 1 Missing ⚠️
crates/rtmp/src/session/server_session.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
- Coverage   50.43%   50.24%   -0.20%     
==========================================
  Files         198      196       -2     
  Lines       16269    16202      -67     
==========================================
- Hits         8206     8141      -65     
+ Misses       8063     8061       -2     
Files with missing lines Coverage Δ
crates/aac/src/lib.rs 89.65% <ø> (ø)
crates/av1/src/config.rs 94.28% <ø> (ø)
crates/av1/src/obu/mod.rs 46.98% <ø> (ø)
crates/av1/src/obu/seq.rs 51.58% <ø> (ø)
crates/av1/src/tests.rs 100.00% <ø> (ø)
crates/bytes-util/src/bit_read.rs 100.00% <100.00%> (ø)
crates/bytes-util/src/bit_write.rs 100.00% <100.00%> (ø)
crates/bytes-util/src/bytes_cursor.rs 100.00% <100.00%> (ø)
crates/exp_golomb/src/lib.rs 100.00% <ø> (ø)
crates/flv/src/flv.rs 81.17% <100.00%> (ø)
... and 20 more
Components Coverage Δ
scuffle-batching 100.00% <ø> (ø)
scuffle-bootstrap 27.15% <ø> (ø)
scuffle-context 100.00% <ø> (ø)
scuffle-ffmpeg 0.00% <ø> (ø)
scuffle-h3-webtransport 0.00% <ø> (ø)
scuffle-http 0.00% <ø> (ø)
scuffle-metrics 42.69% <ø> (ø)
scuffle-pprof 0.00% <ø> (ø)
scuffle-settings 0.00% <ø> (ø)
scuffle-signal 100.00% <ø> (ø)
postcompile 0.00% <ø> (ø)
scuffle-image-processor ∅ <ø> (∅)

@TroyKomodo TroyKomodo changed the title remove bytesio crate create scuffle-bytes-util Jan 9, 2025
crates/bytes-util/src/bytes_cursor.rs Outdated Show resolved Hide resolved
crates/bytes-util/src/bytes_cursor.rs Outdated Show resolved Hide resolved
@lennartkloock
Copy link
Member

?brawl merge

@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

📌 Commit b1a9a32 has been approved and added to the merge queue.

Requested by: @lennartkloock

Approved by: @lennartkloock

@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

⌛ Trying commit b1a9a32 with merge 8b21754...

scuffle-brawl bot added a commit that referenced this pull request Jan 10, 2025
create scuffle-bytes-util
Rename `bytesio` to `scuffle-bytes-util`. We also remove the wrapper types we had and optimize the `Cursor<Bytes>` usage. A lot of what we did with the wrapper types was essentially what `BytesMut` does and what `Vec<u8>` does, which is why most of the usage has been replaced with that.

These changes allow for the code to have fewer copies in the rtmp implementation (I will look to further clean up the tests and code there in a future PR).

The old rtmp flow was such:

- copy bytes from wire into a temporary buffer
- copy that buffer into the chunk decoder (or handshake buffer) buffer
- parse chunks/handshake
- create a temporary buffer to write back result
- copy result from tmp buffer onto wire.

The new flow looks like:

- copy bytes from wire into a buffer
- parse chunks/handshake
- write result into a buffer
- copy result onto the wire

The newer example reuses existing buffers; so each connection will store additional memory (roughly 10kb/connection). As apposed to creating a buffer each time we want to read or write we just reuse an existing one.

We also remove the additional copy to the handshake or chunk decode buffers by having them all share the same buffer (the read buffer).

CLOUD-23

Requested-by: lennartkloock <[email protected]>
Reviewed-by: lennartkloock <[email protected]>
@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

🚨 PR has changed while a merge was in progress, cancelling the merge job.

@TroyKomodo
Copy link
Member Author

?brawl retry

@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

📌 Commit b1a9a32 has been approved and added to the merge queue.

Requested by: @TroyKomodo

Approved by: @lennartkloock

@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

⌛ Trying commit b1a9a32 with merge 55b0764...

@scuffle-brawl
Copy link
Contributor

scuffle-brawl bot commented Jan 10, 2025

🎉 Build successful!
Completed in 7:52

Approved by: @lennartkloock
Pushing 55b0764 to main

@scuffle-brawl scuffle-brawl bot merged commit 55b0764 into main Jan 10, 2025
7 checks passed
@scuffle-brawl scuffle-brawl bot deleted the troy/remove-bytesio branch January 10, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants