-
Notifications
You must be signed in to change notification settings - Fork 35.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
fix various uses of inline #14158
fix various uses of inline #14158
Conversation
…licate definitions. In cpp files, don't make functions with internal linkage inline, since it's unnecessary in that case
Is there any document that can prove this? I don't think they act different when they are in .cpp and .h files |
Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
[decl.inline] say:
which is really the main definition of regarding the distinction of .h vs. .cpp, they do behave the same, however, when a static function appear in a cpp file, there will only ever be one version of it. if a static function appear in a header, it's likely there will be multiple copies. It's potentially more space efficient to just have a single copy, that's why I removed |
utACK ee258a0 Excellent first-time contribution! I'm so glad to see you as a Bitcoin Core contributor @arvidn. I love your work on The high quality standards you strive for in the Welcome to Bitcoin Core! :-) |
@arvidn I'm curious if you found these with grep or other tool? I mean, is this complete? And can we add check to prevent more "wrong" code? |
@promag good question. I used vim for the bulk of the change, specifically:
and
Then I grepped out the templates from the diff that created. So, any code outside of those globs was not included. |
As far as I know, |
@sipa that's exactly right, those are the two effects. I believe it's widely understood that all major compilers these days ignore the hint and base inlining entirely on their own heuristics. It's a fair concern though. I'll see what I can come up with. Are there any performance regression tests by any chance? |
There is |
it appears at least clang does take the Perhaps a better approach would be to split this PR into two. I could revert the removal of |
I put some work into investigating whether any of the inline decisions changed by this patch. Given that it's primarily decided by heuristics, this may differ on GCC. I tested this with clang using the Specifically I ran:
and then the same thing in this branch (after cleaning obviously):
My hope was that the output would be identical, but it wasn't for various reasons. However, all the actual inline decisions were the same. The difference was that some names were mangled differently (presumably because of the linkage change) and some logs quoting lines in the source changed, because the source changed. for example:
(note the additional "L" in the mangled name)
So, at least for for clang, this patch does not change any inlining decisions. |
@arvidn I just observed I very much doubt the same effect would be observed in Bitcoin Core (nothing similarly complex happens here), but I thought I'd point it out as it may mean we need to consider GCC as well. |
Needs rebase |
Still needs rebase, so closing for now. Let me know when you work on this again, so I can reopen. |
This is C++, inline functions in a headers do not need to be
static
. Making it so is a pessimization as it will generate functions with internal linkage in every translation unit including the header. (Note thatinline
in C is different frominline
in C++).Furthermore, a static function in a cpp file already has internal linkage, making it
inline
has no effect.Templates already have an inline-like property of being allowed to be defined multiple times, and having the linker deal with it. Making them
inline
is also redundant.This change does 3 things:
static
from all inlined functions in header filesinline
from allstatic inline
functions in .cpp filesinline
from templates