Repository navigation
Commit bc28558
committed
diagnostics: the unused rule maps its bodies once, and every rule shares the function walk
Two of the four items measured last round, both answered by profiling inside the rule.
**`Unused`: 60 -> 43 ms.** The rule's own split, from a probe added for this (`[unused] … counted tokens 9 ms |
bodies 18 ms | loop 25 ms`, 3 300 declarations and 1 500 locals in a 2 701-line file):
* the identifier counting is 9 ms — one pass over the file's own tokens, already linear;
* the bodies are 18 ms — a walk of the declarations plus one crossing per body;
* the loop was 43 ms, and all of the difference was one line: every *local* mapped its offset into the **rendering**
before asking "is it inside a function body", and `reading_offset_of` is a linear scan of the reading's spans
(three of them). 1 500 locals against ~20 000 spans. The bodies are now mapped into the **file's** coordinates
instead — a few hundred crossings — and the scope question still crosses for the locals that reach it, which is a
handful. The body search is a binary search on the bodies' starts rather than a scan.
**The function-definition walk is shared.** `argument-count`, `missing-return` and `unused` each filtered every
declaration in the file for the shape itself; the predicate is a cast and a declarator inspection, and the three
rules now ask `CheckContext::functions()`, which classifies once per pass — the same argument as the node walk in the
previous commit.
**What was left alone, and why:** `ReturnTypeMismatch`'s 171 ms is inference, not a walk — `CPPLS_NO_INFERENCE=1`
takes it to 3 ms — and the shared `TypeMemo` is already in place (one model per pass, memoised per node), so what
remains is distinct inference. That is the engine's per-expression cost, not a missing cache, and it is the honest
place to stop this round rather than add a cache that would not hit.
`docs/diagnostics-performance.md` §6 records the split and the numbers.
Tests: `cargo test --release --workspace` green (200 suites), clippy `--all-targets` clean.1 parent 16d2ae4 commit bc28558
3 files changed
Lines changed: 96 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
| |||
325 | 328 | | |
326 | 329 | | |
327 | 330 | | |
| 331 | + | |
328 | 332 | | |
329 | 333 | | |
330 | 334 | | |
| |||
594 | 598 | | |
595 | 599 | | |
596 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
597 | 620 | | |
598 | 621 | | |
599 | 622 | | |
| |||
886 | 909 | | |
887 | 910 | | |
888 | 911 | | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
| 912 | + | |
899 | 913 | | |
900 | 914 | | |
901 | 915 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
124 | 137 | | |
125 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
126 | 154 | | |
| 155 | + | |
127 | 156 | | |
| 157 | + | |
| 158 | + | |
128 | 159 | | |
129 | 160 | | |
130 | 161 | | |
131 | 162 | | |
132 | 163 | | |
133 | 164 | | |
| 165 | + | |
134 | 166 | | |
135 | 167 | | |
136 | 168 | | |
137 | 169 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
150 | 177 | | |
151 | 178 | | |
152 | 179 | | |
153 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
154 | 189 | | |
155 | 190 | | |
156 | 191 | | |
| |||
212 | 247 | | |
213 | 248 | | |
214 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
215 | 260 | | |
216 | 261 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
340 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
341 | 353 | | |
342 | 354 | | |
343 | 355 | | |
| |||
0 commit comments