Improve performance of excluded files filter (#5157)

The current algorithm is like "collect all included files and subtract all excluded files".
Collecting all included and all excluded files relies on the file system. This can become slow
when the patterns used to exclude files resolve to a large number of files.

The new approach only collects all lintable files and checks them against the exclude patterns.
This can be done by in-memory string-regex-match and does therefore not require file system accesses.
This commit is contained in:
Danny Mösch
2024-12-25 17:33:33 -05:00
committed by GitHub
parent 03f8c83d0d
commit 152355e36f
14 changed files with 145 additions and 96 deletions
@@ -68,11 +68,20 @@ public extension String {
/// Returns a new string, converting the path to a canonical absolute path.
///
/// > Important: This method might use an incorrect working directory internally. This can cause test failures
/// in Bazel builds but does not seem to cause trouble in production.
///
/// - returns: A new `String`.
func absolutePathStandardized() -> String {
bridge().absolutePathRepresentation().bridge().standardizingPath
}
/// Like ``absolutePathStandardized()`` but with the working directory that's used everywhere else.
var normalized: String {
let cwd = FileManager.default.currentDirectoryPath.bridge().standardizingPath
return bridge().absolutePathRepresentation(rootDirectory: cwd)
}
var isFile: Bool {
if self.isEmpty {
return false