Skip to content

Conversation

@krakow10
Copy link
Contributor

@krakow10 krakow10 commented Nov 8, 2025

I missed a pretty obvious copy optimization here. By constructing the iterator using a slice, we can use the original buffer and avoid copying the data into an intermediate buffer. I was inspired by looking over #530. I'm not actually seeing performance improvements in my benchmarking, even when omitting the interleaved index bounds checks with unsafe. Do interleaved byte reads actually only occupy a very minor portion of the decode process?

Note: The function signature is infallible, but in fact it is possible for the provided slice to be too short, and split_at will panic, similarly to #530. This could be changed to use split_at_checked and generate an EOF io error.

@krakow10 krakow10 changed the title rbx_binary: Eliminate a Copy in Interleaved Iterators rbx_binary: Eliminate Buffer From Interleaved Iterators Nov 8, 2025
@krakow10
Copy link
Contributor Author

krakow10 commented Nov 12, 2025

I've made the executive decision to check the slice length and return an io::Error if it's too short. It's completely a possibility, and it doesn't really make sense to panic on a decode error. I also made this change to #530.

@krakow10
Copy link
Contributor Author

krakow10 commented Nov 15, 2025

I've changed to a trait-based implementation. Even though it's a bit more code, I think it's nicer, and it reduces the diff since it looks the same as the original RbxReadExt functions that it's replacing at the call site.

@krakow10
Copy link
Contributor Author

krakow10 commented Nov 15, 2025

Closing in favour of combining with #530

@krakow10 krakow10 closed this Nov 15, 2025
@krakow10 krakow10 deleted the interleaved branch November 16, 2025 00:32
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