This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Skip (most) predefined macros when scanning for preamble patching.
ClosedPublic

Authored by sammccall on May 7 2022, 2:54 PM.

Details

Summary

This is unneccesary work.
With this change, we skip generating and lexing ~10k of predefines twice.

A dumb benchmark of building a preamble for an empty file in a loop shows:

  • before: 1.90ms/run
  • after: 1.36ms/run

So this should be worth 0.5ms for each AST build and code completion.

There can be a functional difference, but it's very minor.
If the preamble contains e.g. #ifndef __llvm__ ... #endif then before we would
not take it. After this change we will take the branch (single-file mode takes
all branches with unknown conditions) and so gather different directives.

However I think this is negligible:

  • this is already true of non-builtin macros (from included headers). We've had no complaints.
  • this affects the baseline and modified in the same way, so only makes a difference transiently when code guarded by such an #ifdef is being edited

Diff Detail

Event Timeline

sammccall created this revision.May 7 2022, 2:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2022, 2:54 PM
sammccall requested review of this revision.May 7 2022, 2:54 PM

(yes, there's a perverse pleasure in writing 20 lines of commit message for one line of code with no comments. I think in *hindsight* this is obvious enough that it's not worth describing in the code)

Thx, LGTM. I agree that figuring out includes/macros in conditional branches is already best-effort, so I don't think this will result in noticeable regressions.

This revision was not accepted when it landed; it landed in state Needs Review.May 9 2022, 6:34 AM
This revision was automatically updated to reflect the committed changes.