Skip to content

Perf: stop searching inside directories a ** entry already matched (config load 60 to 85 % faster with **/vendor-style entries) - #14624

Merged
alies-dev merged 2 commits into
vimeo:masterfrom
alies-dev:perf-filefilter-glob-prune-v2
Nov 22, 2026
Merged

alies-dev merged 2 commits into
vimeo:masterfrom
alies-dev:perf-filefilter-glob-prune-v2

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

For a <directory> entry with **, such as <directory name="**/vendor"/> in ignoreFiles, Psalm walked every directory below the config's directory. It also walked inside each vendor directory it had already matched, looking for more matches. Psalm loads the config twice per run (before and after its restart), so a big vendor was walked twice. Psalm now stops at a matched directory, because the match already covers everything inside it.

Which project files Psalm analyses or ignores doesn't change, apart from the symlink case below. What does change:

  • UnusedIssueHandlerSuppression lists each matched path once. It no longer lists a match nested inside another match of the same entry (/vendor/ instead of /vendor/a/vendor/, /vendor/; a <file name="pk/**/vendor/**/*.php"/> file reached through two nested matches was listed twice).
  • For a directory entry, Psalm no longer finds a match that it could reach only through a symlink inside another match (vendor/acme/pkg linking to a directory outside the project that has its own vendor). Entries ending in a file pattern (**/vendor/**/*.php) still find such files.

#14559 (a symlink cycle in a ** walk) touches the same function. The two PRs merge cleanly. Both are needed: with this PR alone, a symlink cycle outside any match still hangs.

Measurements

Apple M1 Pro (10 cores, 32 GB), PHP 8.5.12, zend.assertions=1, master 9028ade against this branch (measured at 90f88539c, the same source). drupal's config has its vendor entry in ignoreFiles written as **/vendor; the big Laravel app (a large private application) uses its own config, which ignores packages/**/vendor.

Config::loadFromXMLFile(), 6 loads in one process, two blocks per version alternating (master, branch, branch, master), warm file system cache. The project file set (every PHP file isInProjectDirs() accepts) is identical on both versions.

project first load s, master loads 2 to 6 s, master first load s, branch loads 2 to 6 s, branch
drupal 1.42, 1.13 0.61 to 0.64 0.71, 0.27 0.24 to 0.33 (-60 %)
big Laravel app 0.21, 0.10 0.083 to 0.086 0.026, 0.018 0.013 (-85 %)

Full runs, --no-cache, runs of the two versions alternating (ABAB, then BABA). "outside phases" is the wall time minus the scan, analysis and merge phases: start-up (where the config is loaded, twice because of the restart) and shutdown. A change is marked only where the means differ by more than 2 % (wall 3 %) and by more than the spread of the runs in the cell; single runs are not marked.

project threads runs wall s, master wall s, branch CPU s, master CPU s, branch outside phases s, master outside phases s, branch
drupal 8 3+3 19.4, 18.7, 18.4 17.5, 17.5, 17.6 (-7 %) 85.5, 86.6, 85.2 84.1, 84.3, 84.4 3.52, 2.77, 2.69 1.99, 1.81, 1.88 (-37 %)
drupal 1 1+1 65.6 64.6 65.5 64.5 2.70 1.77
big Laravel app 8 3+3 72.9, 71.5, 71.7 72.1, 71.6, 71.6 296.9, 293.3, 293.8 294.4, 293.1, 292.6 2.28, 2.02, 2.03 1.82, 1.80, 1.75 (-15 %)
big Laravel app 1 1+1 213.4 215.7 213.0 213.6 1.57 1.48

Issues: the full issue lists (type, file, line, column, message, taint trace) are identical in every run, at one and at eight threads.

A <directory> entry such as **/vendor walked every directory under the
base, including the matched vendor directories themselves, only to find
the vendor directories nested in them. Those lie inside a match, so they
don't change which files the filter accepts. A directory matching the
next part of the pattern is now searched only for the rest of it.

This also fixes a <file> entry with two ** levels listing a file twice
when it was reached through two nested matches of the middle part.
getDirectories() no longer lists a match nested in another match of the
same entry.
@alies-dev alies-dev self-assigned this Nov 22, 2026
@alies-dev
alies-dev marked this pull request as ready for review November 22, 2026 02:34
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 89.6 25 691 52 996 682
✅ symfony 3 596 243.9 $\color{gray}{\textsf{-0.6\%}}$ 50 610 98 403 1 528
✅ doctrine-orm 380 19.5 $\color{gray}{\textsf{+0.8\%}}$ 3 481 6 143 0
✅ psl 617 25.1 $\color{gray}{\textsf{+1.0\%}}$ 1 375 5 615 1
✅ phpunit 455 20.0 $\color{gray}{\textsf{-0.2\%}}$ 1 731 3 410 18
✅ php-parser 226 13.6 $\color{gray}{\textsf{+0.1\%}}$ 17 154 21 245 0
✅ tempest 895 36.7 $\color{gray}{\textsf{+1.1\%}}$ 5 047 10 528 252
✅ amphp-amp 45 1.4 $\color{gray}{\textsf{-0.7\%}}$ 29 49 0
✅ webmozarts-assert 272 4.4 $\color{gray}{\textsf{-0.5\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.6 $\color{gray}{\textsf{+1.3\%}}$ 155 434 2
✅ monolog 135 5.6 $\color{gray}{\textsf{+0.2\%}}$ 913 2 479 10
✅ drupal 4 839 180.8 $\color{gray}{\textsf{-0.7\%}}$ 97 591 169 293 583
Total 13 273 642.1 $\color{gray}{\textsf{-0.3\%}}$ 204 354 373 315 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head 55142ff · base 9028ade (merge-base) · workflow run

@alies-dev alies-dev changed the title Perf: stop searching inside directories a ** entry already matched Perf: stop searching inside directories a ** entry already matched (config load 60 to 85 % faster with **/vendor-style entries) Nov 22, 2026
@alies-dev alies-dev added the release:internal The PR will be included in 'Internal changes' section of the release notes label Nov 22, 2026
One data-provider test (5 cases) plus the symlink test, instead of ten methods. Drops the CLI test: the UnusedIssueHandlerSuppression message is implode(', ', [...getFiles(), ...getDirectories()]), which the getFiles/getDirectories assertions already pin.
@alies-dev alies-dev added release:fix The PR will be included in 'Fixes' section of the release notes and removed release:fix The PR will be included in 'Fixes' section of the release notes labels Nov 22, 2026
@alies-dev
alies-dev merged commit 8cf98b0 into vimeo:master Nov 22, 2026
72 checks passed
@alies-dev
alies-dev deleted the perf-filefilter-glob-prune-v2 branch November 22, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:internal The PR will be included in 'Internal changes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant