llvm-project/clang/lib/Tooling
Utkarsh Saxena aa979084df [clang][Syntax] Optimize expandedTokens for token ranges.
`expandedTokens(SourceRange)` used to do a binary search to get the
expanded tokens belonging to a source range. Each binary search uses
`isBeforeInTranslationUnit` to order two source locations. This is
inherently very slow.
By profiling clangd we found out that users like clangd::SelectionTree
spend 95% of time in `isBeforeInTranslationUnit`. Also it is worth
noting that users of `expandedTokens(SourceRange)` majorly use ranges
provided by AST to query this funciton. The ranges provided by AST are
token ranges (starting at the beginning of a token and ending at the
beginning of another token).

Therefore we can avoid the binary search in majority of the cases by
maintaining an index of ExpandedToken by their SourceLocations. We still
do binary search for ranges which are not token ranges but such
instances are quite low.

Performance:
`~/build/bin/clangd --check=clang/lib/Serialization/ASTReader.cpp`
Before: Took 2:10s to complete.
Now: Took 1:13s to complete.

Differential Revision: https://reviews.llvm.org/D99086
2021-03-25 18:54:15 +01:00
..
ASTDiff [openmp] Base of tablegen generated OpenMP common declaration 2020-06-23 10:32:32 -04:00
Core Tooling: Migrate to FileEntryRef in clang::tooling::applyAllReplacements, NFC 2020-12-09 16:31:38 -08:00
DependencyScanning [clang][deps] NFC: Document collector, rename members 2021-03-24 11:58:43 +01:00
DumpTool [AST] Add introspection support for Decls 2021-03-22 23:16:02 +00:00
Inclusions [clang-format] Add option for case sensitive regexes for sorted includes 2020-12-05 16:33:21 +00:00
Refactoring [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI 2021-01-22 13:01:41 +00:00
Syntax [clang][Syntax] Optimize expandedTokens for token ranges. 2021-03-25 18:54:15 +01:00
Transformer [libTooling] Change `addInclude` to use expansion locs. 2021-01-15 03:08:56 +00:00
AllTUsExecution.cpp ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC 2020-12-08 17:33:19 -08:00
ArgumentsAdjusters.cpp [Tooling] Handle compilation databases containing commands with double dashes 2021-03-24 16:01:47 -04:00
CMakeLists.txt [AST] Add introspection support for Decls 2021-03-22 23:16:02 +00:00
CommonOptionsParser.cpp [clang-tooling] Prevent llvm::fatal_error on invalid CLI option 2021-01-29 10:15:06 +01:00
CompilationDatabase.cpp [CompilationDatabase] Pass Twine by const reference instead of by value. NFCI. 2021-01-07 12:53:28 +00:00
Execution.cpp [NFC] Refactor Registry loops to range for 2020-06-19 00:40:10 +01:00
ExpandResponseFilesCompilationDatabase.cpp Remove unused Endian.h includes, NFC 2020-03-11 15:45:34 -07:00
FileMatchTrie.cpp [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json 2020-07-17 18:49:14 +02:00
FixIt.cpp [LibTooling] Add "SourceCode" library for functions relating to source-code manipulation. 2019-04-05 14:05:03 +00:00
GuessTargetAndModeCompilationDatabase.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
InterpolatingCompilationDatabase.cpp [Tooling] Handle compilation databases containing commands with double dashes 2021-03-24 16:01:47 -04:00
JSONCompilationDatabase.cpp [NFC] Reordering parameters in getFile and getFileOrSTDIN 2021-03-25 09:47:49 -04:00
NodeIntrospection.cpp [AST] Add generator for source location introspection 2021-03-15 10:52:44 +00:00
Refactoring.cpp [clang] Adopt new FileManager error-returning APIs 2019-08-01 21:31:56 +00:00
RefactoringCallbacks.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
StandaloneExecution.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
Tooling.cpp [Tooling] Handle compilation databases containing commands with double dashes 2021-03-24 16:01:47 -04:00