Skip to content
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

avoid pre-reading files #5973

Merged
merged 5 commits into from
Jan 29, 2025
Merged

Conversation

OneSadCookie
Copy link
Contributor

Per #5947, files are being read unnecessarily when they have been previously linted and appear in the cache.

To avoid this,

  • remove the test for file emptiness from Linter.init
  • extract the redundant check for this in Rule.lint to a helper, which simplifies Rule.lint and allows it to return non-optional
  • check the helper before calling either Rule.lint or Rule.correct.

@SwiftLintBot
Copy link

SwiftLintBot commented Jan 20, 2025

1 Warning
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
18 Messages
📖 Building this branch resulted in a binary size of 29488.51 KiB vs 29488.71 KiB when built on main (-1% smaller).
📖 Linting Aerial with this PR took 1.75 s vs 0.97 s on main (80% slower).
📖 Linting Alamofire with this PR took 1.29 s vs 1.29 s on main (0% slower).
📖 Linting Brave with this PR took 8.66 s vs 8.7 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 5.59 s vs 5.64 s on main (0% faster).
📖 Linting Firefox with this PR took 11.68 s vs 11.75 s on main (0% faster).
📖 Linting Kickstarter with this PR took 10.53 s vs 10.64 s on main (1% faster).
📖 Linting Moya with this PR took 0.55 s vs 0.55 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 2.95 s vs 2.92 s on main (1% slower).
📖 Linting Nimble with this PR took 0.8 s vs 0.8 s on main (0% slower).
📖 Linting PocketCasts with this PR took 8.71 s vs 8.92 s on main (2% faster).
📖 Linting Quick with this PR took 0.45 s vs 0.46 s on main (2% faster).
📖 Linting Realm with this PR took 4.6 s vs 4.58 s on main (0% slower).
📖 Linting Sourcery with this PR took 2.35 s vs 2.36 s on main (0% faster).
📖 Linting Swift with this PR took 4.74 s vs 4.73 s on main (0% slower).
📖 Linting VLC with this PR took 1.26 s vs 1.26 s on main (0% slower).
📖 Linting Wire with this PR took 18.68 s vs 18.81 s on main (0% faster).
📖 Linting WordPress with this PR took 11.58 s vs 11.67 s on main (0% faster).

Here's an example of your CHANGELOG entry:

* avoid pre-reading files.  
  [OneSadCookie](https://github.com/OneSadCookie)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by 🚫 Danger

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically looks good to me!

Would be great to have a test for linting and correcting empty files with (mock) rules that do/don't support this.

Source/SwiftLintFramework/Models/Linter.swift Outdated Show resolved Hide resolved
@OneSadCookie OneSadCookie force-pushed the osc/dont-preread-files branch from 86e8f3b to bde693d Compare January 26, 2025 07:41
@OneSadCookie OneSadCookie force-pushed the osc/dont-preread-files branch from bde693d to 54bd5bc Compare January 26, 2025 07:47
@OneSadCookie
Copy link
Contributor Author

I've tried to write those tests, but pretty low confidence that that's "the right way"; pointers appreciated.

I tried to see if there was a way to write an integration test that the files' contents aren't read when the cache is populated, but short of modifying SourceKitten to report contents reads, or magical unix shenanigans (I think you can somehow get a pipe at a path so it gets opened like a regular file, maybe you could tell if data was consumed on the pipe?), I don't see how. Definitely open to ideas here, as regressions will be easy.

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to write those tests, but pretty low confidence that that's "the right way"; pointers appreciated.

Looks okay. It shows that that shouldLintEmptyFiles property works at least.

I tried to see if there was a way to write an integration test that the files' contents aren't read when the cache is populated, but short of modifying SourceKitten to report contents reads, or magical unix shenanigans (I think you can somehow get a pipe at a path so it gets opened like a regular file, maybe you could tell if data was consumed on the pipe?), I don't see how. Definitely open to ideas here, as regressions will be easy.

I don't know of a way to do this either.

Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
Tests/FrameworkTests/EmptyFileTests.swift Outdated Show resolved Hide resolved
@SimplyDanny SimplyDanny enabled auto-merge (squash) January 29, 2025 20:22
@OneSadCookie
Copy link
Contributor Author

Thanks for all your help getting this over the line, and attention to detail for the project. I really appreciate it!

@SimplyDanny
Copy link
Collaborator

Thanks for all your help getting this over the line, and attention to detail for the project. I really appreciate it!

You are the one with an eye for the performance details. Keep it up!

@SimplyDanny SimplyDanny merged commit 0460a6c into realm:main Jan 29, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants