Reduce per-file filesystem and gating overhead - #6851
Open
Brett-Best wants to merge 1 commit into
Open
Conversation
- Cache validation read the full attribute dictionary (including an enumeration of all extended attributes) per file just for the modification date; ask for the single resource value instead. - Read a file's emptiness once per file instead of once per rule and file: the check acquired the contents queue lock on every call. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Reduces fixed per-file overhead in SwiftLint’s linting pipeline by avoiding unnecessary filesystem work during cache validation and by reusing a per-file “is empty” computation during rule gating.
Changes:
- Fetch file modification dates via a single URL resource value (
contentModificationDateKey) instead of building the full file attributes dictionary. - Compute
fileIsEmptyonce per file and pass it into rule gating during linting. - Document the performance-oriented change in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Source/SwiftLintFramework/Models/Linter.swift | Threads a per-file fileIsEmpty value through rule linting/gating to reduce repeated file-content synchronization overhead. |
| Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift | Optimizes cache validation by retrieving only the content modification date resource value. |
| CHANGELOG.md | Adds a “Main” entry describing the per-file overhead reductions. |
Comment on lines
70
to
+72
| func shouldRun(onFile file: SwiftLintFile) -> Bool { | ||
| shouldRun(onFile: file, fileIsEmpty: file.isEmpty) | ||
| } |
Generated by 🚫 Danger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Linting each file currently does two avoidable pieces of fixed work:
file.isEmpty, repeatedly acquiring the file contents synchronization path.This asks the URL for only
contentModificationDateKey, then computesfileIsEmptyonce per file and passes it through rule gating.Verification
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift build -c release --product swiftlintDEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test: 370 tests in 73 suites passed..build/release/swiftlint lint --strict --quiet --no-cache Source/SwiftLintFramework/Extensions/FileManager+SwiftLint.swift Source/SwiftLintFramework/Models/Linter.swift: clean.--enable-all-rules: 64,834 before, 64,834 after.Measurement
--only-rule trailing_newlineon DuckDuckGo (6,747 linted files), chosen so that fixed per-filecost dominates rather than rule work. Both binaries interleaved, best of three, on an otherwise
idle machine:
The warm-cache row is the one that exercises the attribute change directly, since validating a
cached entry is what reads the modification date.
For a full
--no-cachelint the end-to-end difference is within machine noise, and is notpresented here as a speedup.
🤖 Generated with Claude Code