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.
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.
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.
Hello, thanks for your comment. Note that this optimization is most efficient if the page size is known statically and
sysconfappears 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.
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.