-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
clang-tidy performance issues in template and consexpr heavy code #86553
Comments
@llvm/issue-subscribers-bug Author: Paul Kirth (ilovepi)
We're getting reports from some of our developers that clang-tidy hangs on a certain test file in the Fuchsia source tree (see https://fxbug.dev/330907651).
After some investigation, I found that it will take clang-tidy about 1 hr 40 min to analyze the file. Using
I've tried to reproduce this behavior with the output from For reference, the reproducer compiles in about 46 seconds, and w/ I'm happy to share the reproducer, but since it isn't exhibiting this behavior I'm not sure it has much value. And aside from checking out the Fuchsia source and running a command against it, I'm not sure what I can provide to aid the investigation. If possible, I'd like to find out:
|
@llvm/issue-subscribers-clang-tidy Author: Paul Kirth (ilovepi)
We're getting reports from some of our developers that clang-tidy hangs on a certain test file in the Fuchsia source tree (see https://fxbug.dev/330907651).
After some investigation, I found that it will take clang-tidy about 1 hr 40 min to analyze the file. Using
I've tried to reproduce this behavior with the output from For reference, the reproducer compiles in about 46 seconds, and w/ I'm happy to share the reproducer, but since it isn't exhibiting this behavior I'm not sure it has much value. And aside from checking out the Fuchsia source and running a command against it, I'm not sure what I can provide to aid the investigation. If possible, I'd like to find out:
|
@ilovepi Are you able to attach preprocessed ffl_tests.cc file ? |
I'll just include everything. Here's the reproducer and a script. I think the only thing that needs to be changed is the path to clang or clang-tidy, but its possible I missed something else that's only available locally for when using the original driver args. |
Forgot to mention I included the |
I have a few ideas about what went wrong and how to fix it. It'll likely take me a couple of days, and the fix should be included in Clang-tidy 19 unless you decide to cherry-pick it. |
Thanks for looking into this so quickly. We run at ToT, and try to release a new compiler for Fuchsia on a weekly cadence so it isn't a problem for us if it won't be in an official LLVM release for ~6 months. AFAIK this isn't blocking anything but this one file from being linted in our CI. We'd like to get that fixed, but having a patch out for review w/in a week is great in my opinion. I am curious though as to the underlying mechanism that causes this issue, so if you can CC me on the fix I'd appreciate it. |
Main problem with performance of this check is caused by hasAncestor matcher, and to be more precise by an llvm::DenseSet and std::deque in matchesAnyAncestorOf. To reduce impact of this matcher, multiple conditions that were checked in check method were copied into ast matcher that is now checked before hasAncestor. Using custom getCheckTraversalKind to exclude template instances that shouldn't be checked anyway is an additional improvment, but gain from that one is low. Tested on ffl_tests.cc, visible reduction from ~442 seconds to ~15 seconds (~96% reduction). Closes llvm#86553
Main problem with performance of this check is caused by hasAncestor matcher, and to be more precise by an llvm::DenseSet and std::deque in matchesAnyAncestorOf. To reduce impact of this matcher, multiple conditions that were checked in check method were copied into AST matcher that is now checked before hasAncestor. Using custom getCheckTraversalKind to exclude template instances that shouldn't be checked anyway is an additional improvement, but gain from that one is low. Tested on ffl_tests.cc, visible reduction from ~442 seconds to ~15 seconds (~96% reduction). Closes #86553
I will keep this issue open for a while, as still some performance improvements are possible in this check. |
We're getting reports from some of our developers that clang-tidy hangs on a certain test file in the Fuchsia source tree (see https://fxbug.dev/330907651).
After some investigation, I found that it will take clang-tidy about 1 hr 40 min to analyze the file. Using
--enable-profile
I got the following timing information.I've tried to reproduce this behavior with the output from
-gen-reproducer=always
, but it seems be behaving differently (e.g., finishing w/in a 2 minutes) using the-cc1
options. Even with the original command (minus the include dirs) and with any required paths, I'm not seeing the same behavior. I'm not sure why using the pre-processed file would be functionally different, but it seems to make a large difference here.For reference, the reproducer compiles in about 46 seconds, and w/
-ftime-trace
I see that 42/46 seconds is in the frontend, nearly all of that instantiating functions, an significant portion evaluating R values.I'm happy to share the reproducer, but since it isn't exhibiting this behavior I'm not sure it has much value. And aside from checking out the Fuchsia source and running a command against it, I'm not sure what I can provide to aid the investigation.
If possible, I'd like to find out:
The text was updated successfully, but these errors were encountered: