Reduce per-file filesystem and gating overhead - #6851
Draft
Brett-Best wants to merge 1 commit into
Draft
Conversation
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) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Still seeing if this can actually be addressed, will move to draft temporarily.
Here's an example of your CHANGELOG entry: * Reduce per-file filesystem and gating overhead.
[Brett-Best](https://github.com/Brett-Best)
[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)note: There are two invisible spaces after the entry's text. Generated by 🚫 Danger |
SimplyDanny
requested changes
Aug 6, 2026
Comment on lines
+70
to
+72
| func shouldRun(onFile file: SwiftLintFile) -> Bool { | ||
| shouldRun(onFile: file, fileIsEmpty: file.isEmpty) | ||
| } |
Brett-Best
force-pushed
the
linter-per-file-overhead
branch
3 times, most recently
from
August 8, 2026 07:31
bcce99b to
d64068a
Compare
SimplyDanny
reviewed
Aug 8, 2026
| // As we need the configuration to get custom identifiers. | ||
| // swiftlint:disable:next function_parameter_count | ||
| func lint(file: SwiftLintFile, | ||
| fileIsEmpty: Bool, |
Collaborator
There was a problem hiding this comment.
Should also be a closure.
Brett-Best
marked this pull request as draft
August 8, 2026 12:06
Brett-Best
force-pushed
the
linter-per-file-overhead
branch
from
August 8, 2026 12:19
d64068a to
9972c01
Compare
- 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. - Cache each rule type's Swift-version eligibility with the shared configuration, keeping version parsing off the per-rule, per-file hot path. - Read a file's emptiness at most once per file, and only when a version-compatible rule needs it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Brett-Best
force-pushed
the
linter-per-file-overhead
branch
from
August 8, 2026 13:08
9972c01 to
1cea10a
Compare
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:
This asks the URL for only
contentModificationDateKey. Swift-version eligibility is computed once per shared configuration and carried alongside each selected rule. Before readingfile.isEmpty, the linter checks whether any version-compatible rule requires empty-file gating, so the value is computed zero or one time per file. Autocorrect keeps the read lazy behind the same version and empty-file gates.Verification
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift build -c release --product swiftlintDEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer swift test: passed.swift test --filter EmptyFileTests: 3 tests passed, including a deferred nonexistent-file regression proving an unsupported rule does not read the file during autocorrect.make bazel_test_tsan: 18/18 targets passed; the affected//Tests:FrameworkTeststarget was rerun after adding the regression test..build/debug/swiftlint lint --strict --quiet --no-cacheon all four changed files: 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.
A separate seven-run
--no-cachecheck of the version-aware gating revision was neutral:2.125s before versus 2.126s after. For a full
--no-cachelint the end-to-end difference iswithin machine noise and is not presented here as a speedup.
🤖 Generated with Claude Code