perf: use FileSystemEnumerator
#1756
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
FileSystemEnumeratorto replaceDirectory.EnumerateFiles, this will only match valid CSharpier file types and skips large always ignored directories, like/binor/.gitNote that this doesn't use
IFileSystem.Directory.EnumerateFilesI've checked the implementation ofDirectoryWrapper->FileSystemEnumerableFactory.UserEntrieswhich internally usesFileSystemEnumerable, so this is functionally the same but skips invalid files and ignored directories.Unfortunately this causes an issue for the
CLI.Testsas it usesMockFileSystemwhich doesn't really callFileSystemEnumerablecausing the tests to fail. I added a fallback check forMockFileSystembut it feels extremely hacky and potentially error prone.IEnumerableinValidFilesEnumerator.gitignoreandcsharpierignorewhile parsing, it would slow things down due to reading files synchronously but it would avoid searching a lot of directories.ValidFilesEnumeratorsearches folders as we'd first have to check for ignore files before we can start yielding files as they may have been ignored.Benchmarks
This change will have a varying impact on different projects. For instance my csharpier project has 20,000 files in it, most of which are probably in
bin,gitand benchmarks results. This will reduce the impact of #1743 and #1740Before
After