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

Improve the performance of put_u8 and put_i8 #669

Closed
wants to merge 2 commits into from

Conversation

YHM404
Copy link

@YHM404 YHM404 commented Jan 31, 2024

When using put_u8/put_i8, it internally wraps the u8/i8 into &[u8], and then calls put_slice(). Wrapping it into &[u8] is an unnecessary operation. So I optimized this step.

Here's the benchmark below:

Before
test put_u8_bytes_mut ... bench: 333 ns/iter (+/- 70) = 384 MB/s

After
test put_u8_bytes_mut ... bench: 271 ns/iter (+/- 8) = 472 MB/s

@seanmonstar
Copy link
Member

This skips some of the length checks making sure there is room for the byte. If the Buf is full, this would be UB.

@YHM404
Copy link
Author

YHM404 commented Jan 31, 2024

This skips some of the length checks making sure there is room for the byte. If the Buf is full, this would be UB.

thx. it's fixed.

@YHM404 YHM404 closed this Feb 11, 2024
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