This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy][NFC] Reduce map lookups in IncludeSorter
Needs ReviewPublic

Authored by njames93 on Jan 17 2022, 1:08 AM.

Details

Summary

Because StringMapEntrys have stable addresses, The IncludeBuckets can be changed to store pointers to entrys instead of the key used for accessing IncludeLocations.
This saves having to lookup the IncludeLocations map as well as creating unnecessary strings.

Diff Detail

Event Timeline

njames93 created this revision.Jan 17 2022, 1:08 AM
njames93 requested review of this revision.Jan 17 2022, 1:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2022, 1:08 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I wonder what motivated the patch. Is this a performance optimization? If so, do you have any measurements?

I wonder what motivated the patch. Is this a performance optimization? If so, do you have any measurements?

I was doing some work on IncludeInserter and just thought, this seems unnecessary. It'd be hard to microbenchmark this, but I'll see what I can rustle up.

Are we waiting on some sort of benchmark before accepting/rejecting this change?

Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2022, 10:22 AM

This change is dangerous, it depends that elements/iterators won't be re-allocated/invalidated during insertion process.
Part with removing double lookup in IncludeSorter::addInclude looks fine, but part that involve IncludeBucket is problematic.
I will try to push part that involve IncludeLocations optimizations.