<functional>: make move_only_function do less work#5328
Merged
StephanTLavavej merged 7 commits intomicrosoft:mainfrom Mar 13, 2025
Merged
<functional>: make move_only_function do less work#5328StephanTLavavej merged 7 commits intomicrosoft:mainfrom
<functional>: make move_only_function do less work#5328StephanTLavavej merged 7 commits intomicrosoft:mainfrom
Conversation
<functiona>: make move_only_function doing less work<functional>: make move_only_function doing less work
<functional>: make move_only_function doing less work<functional>: make move_only_function do less work
StephanTLavavej
approved these changes
Mar 8, 2025
Member
|
Thanks! 😻 On my 5950X I actually observe
However, this case seems unrealistic (how often are users default-constructing and immediately moving), and if the code had originally been written this way, I would never have asked for an additional pointer to be nulled. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
Thanks for improving this code and benchmarking it! ⏱️ 🚀 😻 |
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.
Primarily I treat this more as a clarity improvement.
Yet, the benchmark results prove this PR deserving
performancelabel.Resolves #5316
⏱️ Benchmark results
🥇 Results interpretation
mof_constructis the only that changed more than results variation, it shows some improvement due to doing less work.mof_construct_and_moveaddresses the concern of potential slowdown due to failed store-to-load forwarding.The concern was due to storing zero as one pointer but then loading two pointers, which can be loaded in the same vector register. If the load happens shortly after the store, it has to wait for the store to completely reach the cache, as the wider value cannot be obtained from the narrower store buffer entry.
The situation apparently does not happen, as before the actual two-pointers move, there's vtable obtaining and inspection, which takes enough time for the store to complete.
mof_noneandmof_movegive some idea on the corresponding baseline timings. They are not expected to change.