LWG-3899 co_yielding elements of an lvalue generator is unnecessarily inefficient#5303
Merged
StephanTLavavej merged 1 commit intomicrosoft:mainfrom Feb 20, 2025
Merged
LWG-3899 co_yielding elements of an lvalue generator is unnecessarily inefficient#5303StephanTLavavej merged 1 commit intomicrosoft:mainfrom
StephanTLavavej merged 1 commit intomicrosoft:mainfrom
Conversation
frederick-vs-ja
approved these changes
Feb 18, 2025
StephanTLavavej
approved these changes
Feb 18, 2025
Member
|
Thanks, looks perfect! I've edited the PR title to remove the issue number - it doesn't get linked to anything there, and would appear in the git history of PR titles which otherwise only contain PR numbers. I'll get this merged this week - we have a semi-manual process of merging simultaneously to the GitHub and MSVC-internal repos. |
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
Thanks for implementing this LWG issue resolution, and congratulations on your first microsoft/STL commit! 💚 😻 🎉 This change is expected to ship in VS 2022 17.14 Preview 3. |
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.
Resolves #5111
I decided to look into this issue because I like coroutines and wanted to try contributing something.
It turns out that the implementation is quite straight forward, just adding a
yield_valueoverload taking a generator by lvalue reference which is otherwise the exact same as the overload taking a generator by rvalue reference.Since the LWG paper doesn't state specific numbers and to test the implementation I wrote a short test which I tried with both the current STL (as shipped with VS 17.13.0) and my patched version and in both Debug and Release configurations.
Results on my machine (time per element):
The results are bit noisy across multiple runs but show clearly that the general overload of
yield_value(which is used in the current version) takes almost twice as much time as the generator specialised version (both unoptimised and optimised). This is unsurprising since the general overload wraps the range in an extra generator resulting in two coroutine calls per element. The results also show that the difference disappears in the patched version since the lvalue generator also uses the specialised overload.