[PATCH] D117107: [clangd] Elide even more checks in SelectionTree.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 12 05:51:07 PST 2022


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117107

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117107.399305.patch
Type: text/x-patch
Size: 4901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220112/2bd99ff7/attachment-0001.bin>


More information about the cfe-commits mailing list