Outline the drain to heap logic in TinyVec::push#127
Merged
Lokathor merged 2 commits intoLokathor:mainfrom Jan 14, 2021
Merged
Conversation
Shnatsel
reviewed
Jan 13, 2021
|
|
||
| if let Some(x) = arr.try_push(val) { | ||
| #[inline(never)] | ||
| fn drain_to_heap_and_push<A: Array>( |
Collaborator
There was a problem hiding this comment.
You can also try #[cold] annotation, this should provide branch predictor hints for the match below.
Also, could you add a comment explaining why this code is in a separate function?
Owner
There was a problem hiding this comment.
A comment would be good about what's going on here.
Contributor
Author
There was a problem hiding this comment.
I'm unable to measure a difference between #[inline(never)] and #[cold]. I've opted for #[cold] on the basis that if the optimizer somehow concludes that this function is profitable to inline, that is permitted.
Lokathor
approved these changes
Jan 13, 2021
Owner
|
Looks good. @saethlin i can merge this if you're satisfied. |
Contributor
Author
|
@Lokathor Yes please |
saethlin
added a commit
to saethlin/tinyvec
that referenced
this pull request
Jan 16, 2021
add comparison script Outline the drain to heap logic in TinyVec::push Outline the drain to heap logic in TinyVec::push Use #[cold] and explain the outlining in a comment change gen_remove to rebuild sample Vec with clone instead of push rename outer vec in gen_remove for clarity Swap each element instead of calling rotate_left add more loops to amortize away startup cost, tune tinyvec impls a bit swap instead of rotate_right, explain in comment drop loops again wheee Outline the drain to heap logic in TinyVec::push (Lokathor#127) * Outline the drain to heap logic in TinyVec::push * Use #[cold] and explain the outlining in a comment Swap each element instead of calling rotate_left (Lokathor#128)
saethlin
added a commit
to saethlin/tinyvec
that referenced
this pull request
Jan 19, 2021
add comparison script Outline the drain to heap logic in TinyVec::push Outline the drain to heap logic in TinyVec::push Use #[cold] and explain the outlining in a comment change gen_remove to rebuild sample Vec with clone instead of push rename outer vec in gen_remove for clarity Swap each element instead of calling rotate_left add more loops to amortize away startup cost, tune tinyvec impls a bit swap instead of rotate_right, explain in comment drop loops again wheee Outline the drain to heap logic in TinyVec::push (Lokathor#127) * Outline the drain to heap logic in TinyVec::push * Use #[cold] and explain the outlining in a comment Swap each element instead of calling rotate_left (Lokathor#128)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per #39
This is a strategy I've seen be very useful in other places; keeping code size down by forcibly outlining algorithmically cold paths tends to make a huge difference.