-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Implement P3107R5 optimized <print>
#4821
Implement P3107R5 optimized <print>
#4821
Conversation
82ef338
to
411e94e
Compare
@microsoft-github-policy-service agree |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
<print>
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.
Surprisingly few changes for as big as this is. Very nice work.
This comment was marked as resolved.
This comment was marked as resolved.
…specialize for standard types.
…non-locking format types.
I adjusted the specializations at the last minute, but didn't make the corresponding test changes.
tests/std/tests/P3107R5_enabled_specializations/test.compile.pass.cpp
Outdated
Show resolved
Hide resolved
Thanks, this is incredible! 😻 I pushed individual commits for the remaining issues I noticed, all small (the absence of We merge PRs to the GitHub and MSVC-internal repos in a semi-manual process, batched up to save time. Your PR will be part of the next batch, likely next week. I'll post comments here as I prepare it for merging! |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for implementing this C++23 DR, and congratulations on your first microsoft/STL commit! 😻 🥳 🍰 This change is expected to ship in Preview 1 of whatever comes after VS 2022 17.12 (we don't know what it'll be yet, so we're calling it VS Meow in the Changelog until we do know). |
Fixes #4509
Is my first PR so I expect plenty of fun times and issues 😅
In my benchmarking the non-buffered version is about 400-700ns faster, which is not as much as I would have hoped, but I do not think there is a huge amount of room in the design of format and Window's write API for great gains.
The format API ties the iterator type to everything, so we always must go through _Fmt_iterator_buffer writing char's into the buffer and flushing on demand, so using _fputc_nolock is hard since we never actually do anything character by character for the wrapped iterator and the type is important.
Instead I've generalised the optimization vector and string were doing of a customization point for the wrapped iterator when we flush and used that in these custom iterators to write to the stream or to the console with the parent holding a lock. This avoids need to ever allocate the final std::string or re-take the lock.
If we write to the console we must additionally transcode to wchar_t so we can call WriteConsoleW, I've reduced allocation there as well since it can often fit in a buffer but it is still work being done.
Its still a speedup, and I'm sure there is extra room for gains, but I tried various approaches and this was the "simplest" and reduced the most allocation calls.