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
Avoid branch by adding xfer_align to cf->buff #2036
base: master
Are you sure you want to change the base?
Conversation
Are you sure? |
Yes |
Do you have any benchmark numbers to help support this claim? I'd be surprised if this produced a noticeable difference in overall libarchive performance. When I've done performance profiling in the past, the biggest performance bottlenecks were system calls. |
I applied your suggestion. Thanks! Though it may not have a noticeable effect on performance, I do think this code is better written and more straightforward to other programmers who may see this code. |
We can avoid a branch by not comparing with 0.
|
||
/* | ||
* Set a read buffer pointer in the proper alignment of | ||
* the current filesystem. | ||
*/ | ||
cf->buff = cf->allocation_ptr + s; | ||
cf->buff = cf->allocation_ptr + xfer_align - s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to avoid the branch above if you assume xfer_align
is a power of two. However, the change you've made here actually wastes xfer_align
bytes in the case where the original allocation is already aligned (which should be the common case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I just realized that you can do this correctly, but you need an additional modulo operation:
cf->buff = cf->allocation_ptr + ((xfer_align - s) % xfer_align)
We can avoid a branch by not comparing with 0.