-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Perf optimization] Use boost::container::small_vector #3432
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
Conversation
This appears to be quite beneficial (cppcheck gets twice as fast on some files).
|
I wonder if |
|
Actually this may be of interest: |
sweet!! 👍
yes. I'd rather not add a boost dependency. |
I thought so. ;-) |
|
Looking a bit more into this, it seems getTokenArgumentFunction is called many many times, hence the impact I saw from the cost of std::vector (in the call of getArguments in getTokenArgumentFunction) I don't know if std::vector will still be a little bottleneck after that. |
👍 |
|
Done in #3435 |
|
There are actually a lot of other places where we return vectors of size 1 or 2(such as |
Probably. I played a bit with stack_alloc, it is not very convenient for that, at least a lot less than SmallVector (from llvm or boost): you can't return simply return the vector<short_alloc> because you also need to return the arena, and it is non copyable. So you have to do one of the following:
|
|
I see, I was thinking the arena was stored in the allocator. I did find this simple https://github.com/KonanM/small_vector/blob/master/include/small_vector/small_vector.h I think it requires C++17, but it looks like it could be easily adapted to C++11. |
|
I actually found this library: https://github.com/alandefreitas/small Its header-only(so it should be easy to copy into our external directory). However, this requires C++17. We could create type aliases that fallback on STL containers when using older compilers if we want to use such a library. |
|
Also, caffe2 uses a copy of LLVM's SmallVector class but removes dependencies on extra LLVM constructs: https://github.com/pytorch/pytorch/blob/master/c10/util/SmallVector.h We would just need to define |
for information, I could allow something like: I want that it works to use old compilers but if some optimisation or "side feature" is lost that is fine. |
|
I propose adding at least the alias and use it for cases where the container is slow so it is implicitly documented. I also suggest using a separate header file for this instead of adding it to an existing one so it is only includes in places where it is actually needed. In CMake we could make Boost optional so it is only used when found and add it via a define as suggested by Danial. This would not add a hard dependency and we would not need to change any other build systems for now (as they might go away in the future anyways). Later we can replace it with a smaller and hard dependency. This would be a very small change. Also please profile the code before and after so we only use it in places it is actually needed. |
|
not a hard dependency => sounds good to me. |
|
#3799 adds the SmallVector alias with optional I have a follow-up which switches the most obvious offender over to it. Feel free to adjust other instances afterwards. Please profile before and afterwards so we don't switch over unnecessary usage. |
|
Now that I have another one prepared but that needs some cleanups which cause performance regressions which I need to investigate (and possibly report to the compilers) first. Will be a few days until I have both completely ready. |
|
I posted a draft for another usage of |
|
I did an intermediate improvement by pre-sizing the
|
|
FYI #3919 is close to being ready for review. |
This appears to be quite beneficial (cppcheck gets twice as fast on
some files).
This is a first proposal, it is not supposed to be merged as it is now (it is probably missing some dependencies in the CI, among other things).
I used boost::container::small_vector, but maybe there are other solutions here, especially if we don't want to add a dependency to boost: copying llvm/ADT/SmallVector.h ?, something else ?