Commit 5113084
Carlos Gálvez
[clang-tidy] Avoid matching nodes in system headers
This commit is a re-do of e4a8969,
which got reverted, with the same goal: dramatically speed-up
clang-tidy by avoiding doing work in system headers (which is wasteful
as warnings are later discarded). This proposal was already discussed
here with favorable feedback:
#132725
The novelty of this patch is:
- It's less aggressive: it does not fiddle with AST traversal. This
solves the issue with the previous patch, which impacted the ability
to inspect parents of a given node.
- Instead, what we optimize for is exitting early in each Traverse*
function of MatchASTVisitor if the node is in a system header, thus
avoiding calling the match() function with its corresponding callback
(when there is a match).
- It does not cause any failing tests.
- It does not move MatchFinderOptions outside - instead we add
a user-defined default constructor which solves the same problem.
- It introduces a function "shouldSkipNode" which can be extended
for adding more conditions. For example there's a PR open about
skipping modules in clang-tidy where this could come handy:
#145630
As a benchmark, I ran clang-tidy with all checks activated, on a single
.cpp file which #includes all the standard C++ headers, then measure
the time as well as found warnings.
On trunk:
Suppressed 213314 warnings (213314 in non-user code).
real 0m14.311s
user 0m14.126s
sys 0m0.185s
With this patch:
Suppressed 149399 warnings (149399 in non-user code).
real 0m3.583s
user 0m3.454s
sys 0m0.128s
With the original patch that got reverted:
Suppressed 8050 warnings (8050 in non-user code).
Runtime: around 1 second.
A lot of warnings remain and the runtime is sligthly higher, but we
still got a dramatic reduction with no change in functionality.
Further investigation has shown that all of the remaining warnings are
due to PPCallbacks - implementing a similar system-header exclusion
mechanism there can lead to almost no warnings left in system headers.
This does not bring the runtime down as much, though.
However this may not be as straightforward or wanted, it may even
need to be done on a per-check basis (there's about 10 checks or so
that would need to explicitly ignore system headers). I will leave that
for another patch, it's low priority and does not improve the runtime
much (it just prints better statistics).
Fixes #529591 parent 10e146a commit 5113084
File tree
7 files changed
+74
-12
lines changed- clang-tools-extra
- clang-tidy
- docs
- test/clang-tidy/infrastructure
- clang
- docs
- include/clang/ASTMatchers
- lib/ASTMatchers
7 files changed
+74
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
427 | 431 | | |
428 | 432 | | |
429 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | | - | |
73 | | - | |
74 | 71 | | |
75 | | - | |
76 | 72 | | |
77 | 73 | | |
78 | 74 | | |
79 | 75 | | |
80 | 76 | | |
81 | | - | |
82 | 77 | | |
83 | 78 | | |
84 | 79 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
271 | 274 | | |
272 | 275 | | |
273 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1344 | 1344 | | |
1345 | 1345 | | |
1346 | 1346 | | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
1347 | 1382 | | |
1348 | 1383 | | |
1349 | 1384 | | |
| |||
1473 | 1508 | | |
1474 | 1509 | | |
1475 | 1510 | | |
1476 | | - | |
| 1511 | + | |
1477 | 1512 | | |
1478 | | - | |
1479 | 1513 | | |
1480 | 1514 | | |
1481 | 1515 | | |
| |||
1503 | 1537 | | |
1504 | 1538 | | |
1505 | 1539 | | |
1506 | | - | |
| 1540 | + | |
1507 | 1541 | | |
1508 | | - | |
| 1542 | + | |
1509 | 1543 | | |
1510 | 1544 | | |
1511 | 1545 | | |
| |||
1515 | 1549 | | |
1516 | 1550 | | |
1517 | 1551 | | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
1518 | 1555 | | |
1519 | 1556 | | |
1520 | 1557 | | |
1521 | 1558 | | |
1522 | 1559 | | |
1523 | 1560 | | |
1524 | 1561 | | |
| 1562 | + | |
| 1563 | + | |
1525 | 1564 | | |
1526 | 1565 | | |
1527 | 1566 | | |
| |||
1534 | 1573 | | |
1535 | 1574 | | |
1536 | 1575 | | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
1537 | 1579 | | |
1538 | 1580 | | |
1539 | 1581 | | |
| |||
1543 | 1585 | | |
1544 | 1586 | | |
1545 | 1587 | | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
1546 | 1591 | | |
1547 | 1592 | | |
1548 | 1593 | | |
| |||
1555 | 1600 | | |
1556 | 1601 | | |
1557 | 1602 | | |
1558 | | - | |
| 1603 | + | |
1559 | 1604 | | |
1560 | 1605 | | |
1561 | 1606 | | |
| |||
1573 | 1618 | | |
1574 | 1619 | | |
1575 | 1620 | | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
1576 | 1624 | | |
1577 | 1625 | | |
1578 | 1626 | | |
1579 | 1627 | | |
1580 | 1628 | | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1581 | 1632 | | |
1582 | 1633 | | |
1583 | 1634 | | |
| |||
0 commit comments