[clang] [clang] Do not compute typo-correction suggestions for disabled diagnostics (PR #209694)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 13 09:36:18 PDT 2026


AnonMiraj wrote:


> So this is a time savings only for people who disable those diagnostics

I am not really sure about that, it seems to affect any build, but here are my detailed data.

`isIgnored(ID, Loc)` is location sensitive so it is also true in system headers, and glibc/libstdc++ use GCC attributes clang doesn't implement, so a plain `-fsyntax-only` with no `-W` flags still runs 25 typo scans on `mpl/test/set.cpp` and prints 0 warnings  0.78% of that compile sits in `ComputeMappedEditDistance` (1.12% on a TU that only includes six std headers; `sqlite3.c` has none of them, which is why it's the one benchmark that doesn't move).

Command (run once per TU, once per clang):

```sh
B=~/Documents/prab/bench/boost-src
valgrind --tool=callgrind --callgrind-out-file=/tmp/cg.out --collect-atstart=yes \
  ~/Documents/typogate/clangs/$V/bin/clang -fintegrated-cc1 \
  -std=c++17 -I$B -fsyntax-only $B/libs/mpl/test/<TU>.cpp
grep -m1 '^summary:' /tmp/cg.out
```

| TU                | before  | after          | Δ           |
| ----------------- | -----------------: | -----------------: | ----------: |
| `set.cpp`         | 2,278,219,693      | 2,249,186,071      | −1.274%     |
| `fold.cpp`        | 1,671,378,757      | 1,651,995,461      | −1.160%     |
| `zip_view.cpp`    | 2,162,109,666      | 2,142,792,020      | −0.893%     |
| `partition.cpp`   | 1,740,762,534      | 1,724,426,938      | −0.938%     |
| `multiset.cpp`    | 1,580,733,003      | 1,561,016,794      | −1.247%     |
| `remove_if.cpp`   | 1,632,111,863      | 1,612,230,362      | −1.218%     |
| **TOTAL** | **11,065,315,516** | **10,941,647,646** | **−1.118%** |

Same files with `-w` appended (the configuration the original PR number came from):

| TU              | before  | after          | Δ           |
| --------------- | -----------------: | -----------------: | ----------: |
| `set.cpp`       | 2,268,339,811      | 2,251,499,578      | −0.742%     |
| `fold.cpp`      | 1,674,642,583      | 1,651,972,964      | −1.354%     |
| `zip_view.cpp`  | 2,160,443,820      | 2,136,113,763      | −1.126%     |
| `partition.cpp` | 1,737,989,801      | 1,720,566,826      | −1.002%     |
| `multiset.cpp`  | 1,580,262,408      | 1,559,544,195      | −1.311%     |
| `remove_if.cpp` | 1,626,478,181      | 1,609,044,518      | −1.072%     |
| **TOTAL**       | **11,048,156,604** | **10,928,741,844** | **−1.081%** |

https://llvm-compile-time-tracker.com/compare.php?from=49de424f45389cb757c3cc8c50daf38d024e2314&to=be3ef404b9b911089f54c71ca9f97c4433e5fcfb&stat=instructions%3Au
and the tracker seems to support these results

> So the preprocessor check feels like it should be a net negative rather than a positive (though
> perhaps there's some performance value in checking for the known directives first, but I don't
> have a feel for how expensive that check is to perform).

You're right about `isIgnored`, the known-directive check is the part that pays. 20,000 directives in one `#if 0` block, **Ir per directive**:

| probe (20k directives)      | base  | known-directive check | `isIgnored` alone |
| --------------------------- | ----: | --------------------: | ----------------: |
| `#include <zz_N.h>`  | 6,366 | **−4,910**            | **+147**          |
| `#error msg N`       | 4,982 | −3,854                | +149              |
| `#ifoo_bar_N` (unknown)     | 9,363 | +83                   | +147              |


> The attribute changes seem more likely to buy us something because -Wno-attributes is reasonably
> common. How do the performance numbers compare with just the attribute carve-out?

Same 6 TUs, each built separately:

| part                     | default     | `-w`    | `-Wall -Wextra` |
| ------------------------ | ----------: | ------: | --------------: |
| attribute carve-out only | **−0.937%** | −0.882% | −0.872%         |
| preprocessor part only   | −0.292%     | −0.269% | −0.104%         |
| both           | **−1.118%** | −1.081% | −1.016%         |

So ~80% of the win, at default warnings. Attribute part alone elsewhere: −1.17% on a TU that only
includes six std headers, −0.58% fmt, −0.12% stdexec, −0.06% eigen, −0.00% sqlite3.

> Do the numbers change if we skip only typo correction if the suggestion form is ignored or are the
> time savings from not doing any diagnostic work if the unknown attributes diagnostic is disabled?

They don't change both diagnostics are `InGroup<UnknownAttributes>`, so `isIgnored` answers the
same for both and emitting the (equally ignored) plain form is free. I built that variant too:
−0.867% vs −0.937% on the basket, −96.53% vs −96.63% on the probe. So I kept the simpler
whole-function early return.

> but can we get the performance tool to take a look at this? This pessimizes the 'common' case, so
> I'd like to make sure we're not paying a high cost for some slight improvement for the rest.

You could try the command above, it should give similar results to what is in the table, and from my
testing on other codebases it doesn't seem to be slowing anything noticeably, only a noticeable
improvement or no change.



https://github.com/llvm/llvm-project/pull/209694


More information about the cfe-commits mailing list