[all-commits] [llvm/llvm-project] 408eff: [Clang][SourceManager] optimize getFileIDLocal()

Nick Desaulniers via All-commits all-commits at lists.llvm.org
Thu Jun 25 10:00:11 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 408efffbe4a52bae05f1677a47eb3ccfd5cdc1d3
      https://github.com/llvm/llvm-project/commit/408efffbe4a52bae05f1677a47eb3ccfd5cdc1d3
  Author: Nick Desaulniers <ndesaulniers at google.com>
  Date:   2020-06-25 (Thu, 25 Jun 2020)

  Changed paths:
    M clang/lib/Basic/SourceManager.cpp

  Log Message:
  -----------
  [Clang][SourceManager] optimize getFileIDLocal()

Summary:
A recent Linux kernel commit exposed a performance cliff in Clang. Calls
to SourceManager::getFileIDLocal() when there's a cache miss against
LastFileIDLookup can be relatively expensive, as getFileIDLocal() tries
a few linear probes, then falls back to binary search.  The use of
SourceManager::isOffsetInFileID() is also relatively expensive (both
isOffsetInFileID and getFileIDLocal dominated a trace of the performance
cliff case).

As a FIXME notes (and as @kadircet helpfully noted in review of D80681),
there's a few optimizations we can do here since we've already
identified that an offset is local (as opposed to "loaded").

This patch was forked off of D80681, which additionally did this and
modified some caching behavior, as we expect this change to be less
controversial.

In terms of optimizations, we've already determined that the SLocOffset
parameter to SourceManager::getFileIDLocal() is local in the caller
SourceManager::getFileIDSlow(). Also, there's an early continue in the
binary search loop in getFileIDLocal() that are duplicated in
isOffsetInFileID() as pointed out by @kadircet.

Take advantage of these to optimize the binary search patch, and remove
the FIXME.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits, kadircet, srhines

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82497




More information about the All-commits mailing list