-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++] Optimize std::{,ranges}::{fill,fill_n} for segmented iterators #132665
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
base: main
Are you sure you want to change the base?
Conversation
892e5b2
to
bb949d4
Compare
@llvm/pr-subscribers-libcxx Author: Peng Liu (winner245) ChangesThis patch optimizes Below are the benchmark results comparing the before and after implementations. For reference purposes, we've also provided the benchmarks for Fixes two subtasks outlined in #102817.
|
9d18306
to
d89bca5
Compare
d89bca5
to
b3a4fd9
Compare
2df2a8f
to
5616913
Compare
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.
LGTM with a minor change. Thanks for the optimization!
libcxx/include/__algorithm/fill_n.h
Outdated
__enable_if_t<_Or< _Not<__is_segmented_iterator<_OutputIterator> >, | ||
_Not<__has_random_access_local_iterator<_OutputIterator> > >::value, | ||
int> = 0 |
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.
I think it would be easier to follow if we reused exactly the same enable_if
condition here and below. We could do this by using the following condition here:
__enable_if<!_And<__is_segmented_iterator<_OutputIterator>,
__has_random_access_local_iterator<_OutputIterator> >::value>
And then just this below:
__enable_if<_And<__is_segmented_iterator<_OutputIterator>,
__has_random_access_local_iterator<_OutputIterator> >::value>
This makes it clearer that one is the negation of the other.
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.
Thanks. This is a lot simpler!
b426e8d
to
f780dcc
Compare
f780dcc
to
f128d8a
Compare
This patch optimizes
std::fill
,std::fill_n
,std::ranges::fill
, andstd::ranges::fill_n
for segmented iterators, achieving substantial performance improvements. Specifically, fordeque<int>
iterators, the performance improvements are above 10x for all these algorithms. The optimization also enables filling segmented memory ofdeque<int>
to approach the performance of filling contiguous memory ofvector<int>
.Benchmark results comparing the before and after implementations are provided below. For additional context, we’ve included
vector<int>
results, which remain unchanged, as this patch specifically targets segmented iterators and leaves non-segmented iterator behavior untouched.Fixes two subtasks outlined in #102817.
fill_n
fill