Skip to content

Avoid scanning the filesystem to filter files per check#1262

Open
Wigny wants to merge 2 commits intorrrene:masterfrom
Wigny:fix/avoid-filesystem-scan-in-check-runner
Open

Avoid scanning the filesystem to filter files per check#1262
Wigny wants to merge 2 commits intorrrene:masterfrom
Wigny:fix/avoid-filesystem-scan-in-check-runner

Conversation

@Wigny
Copy link
Copy Markdown
Contributor

@Wigny Wigny commented Feb 13, 2026

We started noticing credo became much slow latelly when trying to execute checks that set files.included glob patterns like the Credo.Check.Refactor.PassAsyncInTestCases.

This slowdown seems to be caused, according to my test, by Credo.Sources.find_in_dir/3, which uses Path.wildcard to list matching file paths from the filesystem, which might be running a recursive scan of the entire project tree.

This PR changes the code to filter the already known file paths in memory using Credo.Sources.filename_matches? instead of listing them from the filesystem.

Tested it in our project, and the slowdown was reduced from several minutes to seconds.

@rrrene
Copy link
Copy Markdown
Owner

rrrene commented Feb 14, 2026

First, thx for the PR!

I don't have access to my dev machine at the moment, but I am reasonably sure that this change will cause problems when piping files via STDIN (via --read-from-stdin) or using the watcher (via --watch).

I will have to verify if these scenarios are sufficiently covered by tests right now (and improve the test suite if not) 👍

@Wigny Wigny force-pushed the fix/avoid-filesystem-scan-in-check-runner branch from de901fe to 326a676 Compare March 3, 2026 19:55
@Wigny
Copy link
Copy Markdown
Contributor Author

Wigny commented Mar 3, 2026

Hey @rrrene, I've pushed a commit that adds some tests that I hope would help to catch problems if the behaviour of 'read from stdin' or 'watcher' changed. Let me know if that is useful or if I'm still missing something on those tests.

Wigny added 2 commits March 3, 2026 16:08
When a check defines custom `files` patterns (e.g. `files: %{excluded: ...}`),
the runner used `Sources.find_in_dir` with `Path.wildcard` to list matching
file paths from the filesystem. This was slow in some cases as the glob
patterns could cause a recursive scan of the entire project tree.

Now the runner filters the already known file paths in memory using
`Sources.filename_matches?` instead of listing them from the filesystem again.
@Wigny Wigny force-pushed the fix/avoid-filesystem-scan-in-check-runner branch from 326a676 to 45cc6c4 Compare March 3, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants