This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl
ClosedPublic

Authored by kuganv on Jan 17 2023, 10:03 AM.

Details

Summary

ASTContext::getRawCommentForDeclNoCacheImpl in this case, extracts the text between
the comment and declaration to make sure if there are no other declarations or preprocessor
directives between comment or declarations.

While using Text.find_first_of or Text.find_last_of is functionally the same,
using Text.find_last_of terminates fast in the presence of such.

Especially in generated code with sparse comments, it takes longer
to bailout when there is code in-between. Searching from last
(with find_last_of) bails out faster.

This shows up in perf profiles with clangd in some auto-generated code.
ASTContext::getRawCommentForDeclNoCacheImpl showing as much as 18.2% in this
case. With find_last_of, this drops to 2.8%.

Diff Detail

Event Timeline

kuganv created this revision.Jan 17 2023, 10:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 10:03 AM
Herald added a subscriber: kadircet. · View Herald Transcript
kuganv updated this revision to Diff 489882.Jan 17 2023, 10:43 AM
kuganv edited the summary of this revision. (Show Details)

Updating the summary.

kuganv updated this revision to Diff 494242.EditedFeb 2 2023, 3:33 AM

Rebasing the diff to latest main

kuganv published this revision for review.Feb 2 2023, 8:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 8:30 AM
kuganv updated this revision to Diff 494870.Feb 4 2023, 10:44 PM

Rebasing branch.

kuganv edited the summary of this revision. (Show Details)Feb 20 2023, 10:39 PM
kuganv added reviewers: gribozavr2, aaron.ballman, hans.
aaron.ballman accepted this revision.Feb 21 2023, 6:38 AM

LGTM! You should probably put "NFC" into the patch title when landing the changes though, so it's more clear as to why there's no test coverage.

Do you think this warrants adding a release note to let users know about the performance improvement?

This revision is now accepted and ready to land.Feb 21 2023, 6:38 AM
kuganv retitled this revision from Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl to [NFC] Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl.Feb 21 2023, 7:14 AM

LGTM! You should probably put "NFC" into the patch title when landing the changes though, so it's more clear as to why there's no test coverage.

Do you think this warrants adding a release note to let users know about the performance improvement?

Thanks for the review. I have updated the title with NFC. This may not be significant enough to require update on release notes.

This revision was automatically updated to reflect the committed changes.