[PATCH] D79834: Speed up preamble building by replacing the slow translateFile call by a new, faster isMainFile check
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 13 13:04:02 PDT 2020
arphaman added a comment.
In D79834#2034666 <https://reviews.llvm.org/D79834#2034666>, @jkorous wrote:
> IIUC the issue is that `SourceManager::translateFile()` basically consists of two blocks of code:
>
> // First, check the main file ID, since it is common to look for a
> // location in the main file.
> if (MainFileID.isValid()) {
> bool Invalid = false;
> const SLocEntry &MainSLoc = getSLocEntry(MainFileID, &Invalid);
> if (Invalid)
> return FileID();
>
> if (MainSLoc.isFile()) {
> const ContentCache *MainContentCache =
> MainSLoc.getFile().getContentCache();
> if (MainContentCache && MainContentCache->OrigEntry == SourceFile)
> return MainFileID;
> }
> }
>
>
> and
>
> // The location we're looking for isn't in the main file; look
> // through all of the local source locations.
> ...
>
>
> The comments suggest that the first block is a heuristic related to our case and the second block I would assume being the expensive part. `SourceManager::getFileEntryRefForID` implementation seems similar to the first block.
>
> It makes sense to me to avoid the expensive search. I'm just wondering - how much speedup do we get with caching the value?
Good question, let me check if caching can be avoided.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79834/new/
https://reviews.llvm.org/D79834
More information about the cfe-commits
mailing list