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

(Packable) Pack and unpack byte buffers faster #26

Merged
merged 7 commits into from
Feb 21, 2022
Merged

(Packable) Pack and unpack byte buffers faster #26

merged 7 commits into from
Feb 21, 2022

Conversation

pvdrz
Copy link
Contributor

@pvdrz pvdrz commented Feb 17, 2022

This PR changes the Packable implementations of Vec<T>, Box<[T]>, VecPrefix<T, B> and BoxedSlicePrefix<T, B> in order to specialize them when T is equal to u8.

Before this changes. packable would do something like

for item in self.iter() {
     item.pack(packer)?;
}

to pack any byte buffer, meaning that each byte will trigger one write in the packer. With the changes proposed here. Byte buffers are packed and unpacked in a single read/write. Some benchmarks show a 6x performance improvement.

I ran the test suite of packable using miri given that this code relies on unsafe heavily, No issues were found.

packable/packable/src/packable/array.rs Outdated Show resolved Hide resolved
packable/packable/src/packable/vec.rs Outdated Show resolved Hide resolved
packable/packable/src/packable/box.rs Show resolved Hide resolved
@thibault-martinez
Copy link
Member

Why is a lot of format being changed when the CI wasn't complaining about it ?

@pvdrz
Copy link
Contributor Author

pvdrz commented Feb 21, 2022

Why is a lot of format being changed when the CI wasn't complaining about it ?

Because we didn't have a rustfmt.toml before. That's why cargo +nightly fmt was not merging the imports.

@thibault-martinez
Copy link
Member

Why is a lot of format being changed when the CI wasn't complaining about it ?

Because we didn't have a rustfmt.toml before. That's why cargo +nightly fmt was not merging the imports.

Ah my bad, I missed the fact you added it.

@pvdrz pvdrz merged commit 90ca5c6 into iotaledger:main Feb 21, 2022
@pvdrz pvdrz deleted the faster-bytes branch February 21, 2022 21:07
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.

None yet

2 participants