Skip to content

splitstream: Drop an unsafe #96

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

Merged

Conversation

cgwalters
Copy link
Collaborator

This one didn't have a SAFETY comment; looking through git log here I do see:

It no longer does internal buffer allocations when reading tar headers, saving
another ~10% off the total time to print a merged dumpfile.

However, it looks like that was going from allocation-per-read to "read into a global buffer", which we're still doing here. I didn't measure performance here, but I think
we have other performance worries and it's not worth carrying an unsafe for this.

In very hot I/O paths one can measure the impact of zero-initializing, but I'm doubtful of that here.

Just looking at the bigger picture here I think
instead of a generic R: Read we should take
a BufReader and then use fill_buf on it,
which is intended for this use case.

Anyways for now just drop the unsafe.

Also add tests.

This one didn't have a `SAFETY` comment; looking through
git log here I do see:

> It no longer does internal buffer allocations when reading tar headers, saving
> another ~10% off the total time to print a merged dumpfile.

However, it looks like that was going from allocation-per-read
to "read into a global buffer", which we're still doing here.
I didn't measure performance here, but I think
we have other performance worries and it's not worth
carrying an `unsafe` for this.

In very hot I/O paths one *can* measure the impact of
zero-initializing, but I'm doubtful of that here.

Just looking at the bigger picture here I think
instead of a generic `R: Read` we should take
a `BufReader` and then use `fill_buf` on it,
which is intended for this use case.

Anyways for now just drop the `unsafe`.

Also add tests.

Signed-off-by: Colin Walters <[email protected]>
Copy link
Collaborator

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

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

I agree that I'd prefer to drop the unsafe here, even if it costs us a bit.

Rustix has a really cool new buffer approach that I'd love to use here, but unfortunately it's not for the Read trait. It seems like Rust is still having trouble making up its mind about what to do here: rust-lang/rust#117693

Thanks for the tests!

@allisonkarlitskaya allisonkarlitskaya merged commit b9f6e06 into containers:main Apr 7, 2025
19 of 20 checks passed
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.

2 participants