microsoft / STL

MSVC's implementation of the C++ Standard Library.
Other
10.07k stars 1.48k forks source link

Reduce inclusion for `<queue>` and `<stack>` #4707

Closed frederick-vs-ja closed 3 months ago

frederick-vs-ja commented 3 months ago

Towards #3599.

Test options

Test programs

#include <stack>
int main() {}
#include <queue>
int main() {}

Results

On my old laptop, the changes reduced the consumed time

Notes

Escape hatch _LEGACY_CODE_ASSUMES_QUEUE_INCLUDES_ALGORITHM can be used to restore the inclusion of <algorithm>.

MSVC-internal changes are needed due to the new internal headers.

StephanTLavavej commented 3 months ago

After thinking about the changes, I'm not sure whether we should merge this. Extracting the heap algorithms is fine, but I'm uncomfortable with the magnitude of the ranges changes. The diff is easy enough to review, but it ends up splitting apart one of the STL's most complicated headers, and in a complicated way. Ultimately it's "stuff that ranges::to needs" but that ends up being a lot of machinery. Throughput is generally desirable but I'm not convinced that <queue> and <stack> are popular enough to be worth this.

I'm also deeply concerned about splitting up overloads of ranges::to - users are notoriously undisciplined about including what they need, but the unspecified behavior that they get should ideally be all-or-nothing, it's very confusing to get some overloads but not others. However, that would be easily fixable, so it's not my real concern about merging this.

StephanTLavavej commented 3 months ago

I thought about this some more and I think I can resolve my concerns with some simple changes. Stand by...

StephanTLavavej commented 3 months ago

I pushed commits:

StephanTLavavej commented 3 months ago

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

StephanTLavavej commented 3 months ago

Thanks for queuing up this giant stack of throughput improvements! :joy_cat: :tada: :cat: