-
Notifications
You must be signed in to change notification settings - Fork 30
Make unsound code opt-in. #51
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
base: main
Are you sure you want to change the base?
Conversation
// the latter from seeing it with `not(debug_assertions)`. | ||
#[cfg(all(feature = "unsound", not(debug_assertions)))] | ||
{ | ||
let page_size = 4096; |
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.
Hello
I was skimming rust serialization libraries and somewhat ended up here.
I'm not 100% sure, but I think that for posix systems the hardcoded page size could be replaced by something likesysconf(PAGE_SIZE);
(man sysconf) then in theory be sound on compliant posix systems.
Feel free to take or toss my comment
have a nice day.
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.
Hello, thanks for your comment. Note that this optimization is most efficient if the page size is known statically and sysconf
appears to retrieve it at runtime. AFAIK 4096 is safe because the page size won't be lower than 4096.
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.
Hello, thanks for your comment. Note that this optimization is most efficient if the page size is known statically and
sysconf
appears to retrieve it at runtime. AFAIK 4096 is safe because the page size won't be lower than 4096.
Oh makes sense for the compile time optimisations.
Sysconf at runtime could also be used to choose the correct implementation something akin to:
if sysconf(SC_PAGESIZE) == 4096 { // or using something like a lazy static
// read_mem aligned
} else {
ptr.copy_non_overlapping();
}
Downside: using sysconf would introduce a dependency on libc.
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.
Well a higher page size wouldn't require falling back to copy_non_overlapping
. It would just slightly reduce the probability of the fallback, as the fast path could copy over 4096 byte boundaries within the larger page. The run-time overhead of this check (at least one predicted branch) might outweigh the benefits of this.
A lower page size would require something like this but, AFAIK, that's not possible.
Fixes #50
Benchmarked on i7-7700k
Edit: need to benchmark again to show worst case performance difference.