[all-commits] [llvm/llvm-project] 07f9fb: [clangd] Elide even more checks in SelectionTree.

Sam McCall via All-commits all-commits at lists.llvm.org
Thu Jan 13 13:28:09 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 07f9fb8b51417ec3e6f46508e1b5ef78287b32ad
      https://github.com/llvm/llvm-project/commit/07f9fb8b51417ec3e6f46508e1b5ef78287b32ad
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-01-13 (Thu, 13 Jan 2022)

  Changed paths:
    M clang-tools-extra/clangd/Selection.cpp
    M clang-tools-extra/clangd/unittests/SelectionTests.cpp

  Log Message:
  -----------
  [clangd] Elide even more checks in SelectionTree.

During pop() we convert nodes into spans of expanded syntax::Tokens.
If we precompute a range of plausible (expanded) tokens, then we can do an
extremely cheap approximate hit-test against it, because syntax::Tokens are
ordered by pointer.

This would seem not to buy anything (we don't enter nodes unless they overlap
the selection), but in fact the spans we have are for *newly* claimed ranges
(i.e. those unclaimed by any child node).

So if you have:
   { { [[2+2]]; } }
then all of the CompoundStmts pass the hit test and are pushed, but we skip
full hit-testing of the brackets during pop() as they lie outside the range.

This is ~10x average speedup for selectiontree on a bad case I've seen
(large gtest file).

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




More information about the All-commits mailing list