This is an archive of the discontinued LLVM Phabricator instance.

[clang] Optimize storage and lookup of analyzer options
ClosedPublic

Authored by jansvoboda11 on Nov 2 2022, 8:26 AM.

Details

Summary

This patch moves llvm::sort() from AnalyzerOptions constructor to initialization of local static variable in isUnknownAnalyzerConfig().

This avoids unnecessary work, which can speed up Clang tools that initialize lots of CompilerInvocations (and therefore AnalyzerOptions).

Diff Detail

Event Timeline

jansvoboda11 created this revision.Nov 2 2022, 8:26 AM
Herald added a project: Restricted Project. · View Herald Transcript
jansvoboda11 requested review of this revision.Nov 2 2022, 8:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 8:26 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Are you sure about the speedup?
When I looked at the implementation of the StringSwitch, it boiled down to an if-else chain under the hood.

steakhal accepted this revision.Nov 24 2022, 7:27 AM

BTW the change itself looks good to me.

This revision is now accepted and ready to land.Nov 24 2022, 7:27 AM
jansvoboda11 planned changes to this revision.Dec 2 2022, 10:57 AM

Are you sure about the speedup?
When I looked at the implementation of the StringSwitch, it boiled down to an if-else chain under the hood.

You're right. I assumed StringSwitch was more sophisticated than that. This patch provides speedup for my use-case, which involves constructing lots of AnalyzerOptions instances, but no calls to AnalyzerOptions::isUnknownAnalyzerConfig(). I'll spend more time on this and make sure I don't regress the lookup. (Unfortunately, std::sort is only constexpr in C++20 onwards, so I can't just sort the options at compile-time.)

Move from llvm::StringSwitch back to binary search on sorted vector

This revision is now accepted and ready to land.Apr 20 2023, 1:17 PM
jansvoboda11 requested review of this revision.Apr 20 2023, 1:19 PM
jansvoboda11 edited the summary of this revision. (Show Details)
steakhal accepted this revision.Apr 20 2023, 9:40 PM

I liked the idea of sorting these options at compile time.
I think the most dummy sort should work just fine inthis case, as the number of elements are not that large.
Do you think worth it?

Anyway , I think moving the runtime sort out of the ctor is a good middleground. Thank you.

This revision is now accepted and ready to land.Apr 20 2023, 9:40 PM

Sorting at compile-time would be nicer, but I don't have the bandwidth to implement something like that. I'll leave a FIXME in case someone wants to pick it up. Thanks for the review!