-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test for emptiness is very slow #5947
Comments
From what I see, the cache is checked before the content is tested for emptiness. So how did you come up with the assumption that the |
I used Instruments to profile swiftlint, when running on my own project. The call from |
(I also confirmed that by replacing |
After a brief glimpse on the code, it looks like the Looks like we could give this a try. |
diff --git a/Source/SwiftLintFramework/Models/Linter.swift b/Source/SwiftLintFramework/Models/Linter.swift
index 68f111fdc..5c85aad4c 100644
--- a/Source/SwiftLintFramework/Models/Linter.swift
+++ b/Source/SwiftLintFramework/Models/Linter.swift
@@ -226,12 +226,7 @@ public struct Linter {
self.configuration = configuration
self.compilerArguments = compilerArguments
- let fileIsEmpty = file.isEmpty
let rules = configuration.rules.filter { rule in
- if fileIsEmpty, !rule.shouldLintEmptyFiles {
- return false
- }
-
if compilerArguments.isEmpty {
return !(rule is any AnalyzerRule)
} Unfortunately, that results in changed user-facing behavior:
|
This is a bug. While linting checks for emptiness in combination with |
New Issue Checklist
Bug Description
I work on a project with a large number (~12000) of swift files. SwiftLint's cache does a good job of avoiding linting them when they haven't changed, which means that vast majority of the time we spend waiting for swiftlint is in its "setup costs". One of those costs is in determining whether to avoid linting the file because it is empty. This is done by this function at the bottom of
Linter.swift
:Because this accesses the
contents
property, this forces reading all 12000 swift files into memory, just to know if they're empty or not. This costs several seconds of execution time. That doesn't matter if they're then going to be linted anyway, but it does matter when they're unchanged from the last run and will skip linting.I intended to contribute a fix for this, but it's not at all obvious to me what a good approach would be — this sits right at the intersection of SwiftLint and SourceKitten. Perhaps we should gather file sizes during the directory traversal, store them somewhere, and only read the file if the size == 1?
Environment
SwiftLint version (run swiftlint version to be sure)
0.57.1
Xcode version (run xcodebuild -version to be sure)
Xcode 16.2
Build version 16C5032a
Installation method used (Homebrew, CocoaPods, building from source, etc)
Downloaded from release tag
Configuration file:
n/a
The text was updated successfully, but these errors were encountered: