This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Optimize performance of RenamerClangTidyCheck
ClosedPublic

Authored by PiotrZSL on May 2 2023, 10:52 PM.

Details

Summary

Refactor RenamerClangTidyCheck to achieve better performance
by removing object copies, duplicated function calls and by
using RecursiveASTVisitor.

Measured -72% execution time on bugprone-reserved-identifier.

Diff Detail

Event Timeline

PiotrZSL created this revision.May 2 2023, 10:52 PM
Herald added a project: Restricted Project. · View Herald Transcript
PiotrZSL requested review of this revision.May 2 2023, 10:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 10:52 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
njames93 accepted this revision.May 5 2023, 7:05 AM

Mostly looks good, just a few small nits

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
48

What's the purpose of using hash_combine instead of just adding the 2 hashes together, there is enough entropy in the hashes that a simple operation makes more sense?

200–208

What is the reason for visiting template instantiations?

494

Instead of this nasty const cast, you can just use Visitor.TraverseAST(*Result.Context);

This revision is now accepted and ready to land.May 5 2023, 7:05 AM
PiotrZSL marked 3 inline comments as done.May 5 2023, 10:32 AM
PiotrZSL added inline comments.
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
48

Habit, hash_combine sounded better here, I can change this to +.

200–208

Tests were failing, some method overrides are known only when we visit template instances. Without this code related to "Fix overridden methods" (line 281) were not executed properly.
And as an result overridden virtual methods in template classes were not "fixed". Previously it worked in same way.

494

Yes I know, but it looked strange when we register matcher for something, and then in check we don't use that something.
I can change this.

PiotrZSL updated this revision to Diff 519924.May 5 2023, 10:33 AM
PiotrZSL marked 3 inline comments as done.

Use operator + instead of hash_combine.
Use TraverseAST.