-
-
Notifications
You must be signed in to change notification settings - Fork 93
Interleaved forward links #220
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: master
Are you sure you want to change the base?
Conversation
500b45a to
37f7db9
Compare
| assert!(offset_of!(Node, fwd_links) + size_of::<LinkBuffer>() == size_of::<Node>()) | ||
| } | ||
|
|
||
| (fwd_link_len + BLOCK_SIZE - 1 - LINKS_IN_NODE) / BLOCK_SIZE |
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.
| (fwd_link_len + BLOCK_SIZE - 1 - LINKS_IN_NODE) / BLOCK_SIZE | |
| (fwd_link_len - LINKS_IN_NODE).div_ceil(BLOCK_SIZE) |
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.
Wouldn't that result in undefined behaviour when LINKS_IN_NODE is larger than fwd_link_len?
I guess combined with saturating sub it would work out.
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.
Sorry, I missed that. Yeah, adding saturating_sub will work. The branch is fine as this section isn't performance-critical.
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.
I must point out that integer overflow/underflow is not UB in Rust. Even in C and C++ only signed integer overflow is UB. Rust integer overflow is well-defined and will just wrap around. The whole design goal of Rust is to make it impossible to have UB unless you're using unsafe.
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.
Uhm ok interesting, but overflow is still not desired here and like you said saturating_sub is fine because its not performance critical so I used that approach.
Even if without it it will likely work out since it will likely result in basically the same code I had before but someone reading the code can't really see that since they just see the div and not whats inside.
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.
For performance critical code we should however use the code I had before even without the saturating_sub the div_ceil does infact not result in the same code.
https://godbolt.org/z/he4GE693z
|
Doing some more benchmarks this change seems to pretty significantly decrease the performance of flush from ~2.5ms to ~4ms. |
Would storing the valid node indices instead of computing them on the fly on every flush solve this regression? |
Doing this reduces the overhead and it now takes ~3ms instead which is a more acceptable amount. |
This put the forwards links at the end of Node, when the forward links don't fit into the Node extra nodes will simply be inserted which will be skipped over when iterating.
This results in not having to go to a separate area in memory when looking up the forward links and not even having to load in an extra cache-line when there are less than 6 forward links.
This does have the disadvantage of making iterating a bit more complicated.
Additionally this requires unsafe and is a bit error prone, I tried to minimize potential error by minimizing magic numbers and putting in asserts.
Benchmarks:
rtps for
tickn(50_000)with1000samples for iris mandlebrot benchmark (ran twice in a row):From this we can see about a 5.6% speedup.
master (https://github.com/MCHPR/MCHPRS/tree/a179ab1be44dd44fa3f20ba67195a7f147ab06f2)
old (https://github.com/BramOtte/MCHPRS/tree/refactor-forward-links-unsafe):
(this seems to be within margin of error from master)
This PR: