Skip to content

Conversation

miscco
Copy link
Contributor

@miscco miscco commented Jan 7, 2022

This adds optimizations for std::vector<:ghost:> to make it a bit more useful.

I also added a new subproject for benchmarks. I tried to make it as clean as possible but my CMake skills are limited.

There is one big wrinkle regarding benchmarks in that I currently use an installed version of benchmark. I am not sure if it is possible to link against our produced libraries without any linker errors. As I am currently using header only code I postponed adding benchmark as a subproject for another time.

I only added the x64-Release target for now and will wait until there is a decision on how to name things before adding other targets.

For posterity, I also did some experimentations around using lit for generating and running the benchmarks. But the result was really ugly and also a bit unwieldly as I was not able to make it print out the results of a passed test.

I am also not sure whether there is really value added in testing different standard modes. However, clang vs MSVC would definitely be worthwile

@miscco miscco requested a review from a team as a code owner January 7, 2022 12:23
@miscco miscco changed the title Vector bool copy Optimize std::vector<:ghost:> copy algorithms Jan 7, 2022
@miscco miscco force-pushed the vector_bool_copy branch 2 times, most recently from a37cddd to 4376f0e Compare January 7, 2022 13:10
@miscco
Copy link
Contributor Author

miscco commented Jan 7, 2022

Here are the benchmark results
Current results:
Before

With this PR
After

static random_device rd;
static mt19937 gen{random_device{}()};
vector<bool> result(size);
generate_n(result.begin(), size, []() { return bernoulli_distribution{0.5}(gen); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary ()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, I thought that this is only C++20 and I would want to be able to run the tests in earlier standard modes too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been there since lambdas introduction: https://godbolt.org/z/7cnWEMa6G

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove () here we should on line 17 in the previous file as well.

}

template <class _VbIt, class _OutIt>
_CONSTEXPR20 _OutIt _Copy_vbool(_VbIt _First, _VbIt _Last, _OutIt _Dest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm questioning having this in the header, created #2462

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether we should make them static methods inside of vector itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think method vs free function and in fully header / mostly in .cpp are orthogonal questions.
I have no opinion on method vs free function.

@miscco
Copy link
Contributor Author

miscco commented Jan 7, 2022

Can someone tell me whats wrong with the standard library header units?

@miscco
Copy link
Contributor Author

miscco commented Jan 7, 2022

Urgh looks like it is concerned about unreachable code because we always return for vbool

@CaseyCarter CaseyCarter added the performance Must go faster label Jan 7, 2022
@AlexGuteniev
Copy link
Contributor

A benchmark to consider to add when this is merged: #804 (comment)

@jonwil
Copy link

jonwil commented Jan 8, 2022

I didn't know 👻 was a valid type name in C++...
What is it actually supposed to be (its not clear from the PR)

@SuperWig
Copy link
Contributor

SuperWig commented Jan 8, 2022

It's the spooky std::vector<bool>

Copy link
Contributor

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review

README.md Outdated
[documentation](https://github.com/google/benchmark/blob/main/docs/user_guide.md#running-a-subset-of-benchmarks))

Right now the tests depend on an externally installed benchmark library. This can be done via `vcpkg install benchmark`.
However, it has the drawback that it is not possible to benchmark code that links into the libraries provided by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What "has the drawback"? Does "it is not possible to benchmark code that links into the libraries" mean that benchmarks can only use core headers? If so, we need to provide more explanation. If not, we need to clarify what it's trying to say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped that whole sentence because i actually never really tried

static random_device rd;
static mt19937 gen{random_device{}()};
vector<bool> result(size);
generate_n(result.begin(), size, []() { return bernoulli_distribution{0.5}(gen); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove () here we should on line 17 in the previous file as well.

@StephanTLavavej

This comment was marked as resolved.

@CaseyCarter

This comment was marked as resolved.

Co-authored-by: Casey Carter <[email protected]>
@miscco
Copy link
Contributor Author

miscco commented Feb 17, 2022

Note I left the whole vector bool tests disabled for EDG because it internally relies on vector which essentially breaks all the tests

@StephanTLavavej
Copy link
Member

There's a merge conflict with main here.

@strega-nil-ms
Copy link
Contributor

Assigning myself to help merge the benchmarks into the fancy benchmarking stuff added in #2780

@strega-nil-ms
Copy link
Contributor

@miscco any interest in reviving this PR as of right now? Or should I mark draft?

@miscco
Copy link
Contributor Author

miscco commented Jul 8, 2022

There is definitely interest, but no time.

I just started a new job and we are moving later this month. So I would not expect any work this month

@strega-nil-ms
Copy link
Contributor

Alright! I heard about your new job, good luck with that!!! I'm really happy for you 😁, and also good luck with moving!

I'll mark as draft for now; please ping me on the discord once you're ready to work on it again 😃

@strega-nil-ms strega-nil-ms marked this pull request as draft July 8, 2022 17:29
@frederick-vs-ja
Copy link
Contributor

I wonder whether rotation (used in #3021) should be similarly optimized...

@StephanTLavavej
Copy link
Member

We talked about this at the weekly maintainer meeting (first of the new year! 😸). While we remain interested in optimizing algorithms for vector<bool>, this specific PR is steadily becoming outdated with respect to the current state of main, and at this time neither @miscco nor the maintainers have capacity to bring this PR up to date. Therefore, we're going to close this without merging, but we will happily consider a new PR if anyone wants to restart this work. Thanks again @miscco for looking into this area! 😻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants