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

Allow selective caching for --fix and --diff #8316

Merged
merged 1 commit into from
Oct 29, 2023
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Oct 28, 2023

Summary

If a file has no diagnostics, then we can read and write that information from and to the cache, even if the fix mode is --fix or --diff. (Typically, we can't read or write such results from or to the cache, because --fix and --diff have side effects that take place during diagnostic analysis (writing to disk or outputting the diff).) This greatly improves performance when running --fix on a codebase in the common case (few diagnostics).

Closes #8311.
Closes #8315.

@charliermarsh charliermarsh added the performance Potential performance improvement label Oct 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh requested a review from zanieb October 28, 2023 22:35
Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Nice. Should we retain a note about why we don't always cache?

@charliermarsh charliermarsh enabled auto-merge (squash) October 29, 2023 16:03
@charliermarsh charliermarsh merged commit 86cdaea into main Oct 29, 2023
14 checks passed
@charliermarsh charliermarsh deleted the charlie/cache branch October 29, 2023 16:06
@lukaspiatkowski
Copy link
Contributor

I can confirm this solves #8311, second run of ruff --fix took 0.13s on my repo as expected.

@charliermarsh
Copy link
Member Author

Nice, thanks for testing on main! Appreciate it!

@charliermarsh
Copy link
Member Author

I'd expect ruff --fix to still be much slower if most files have diagnostics, since we only skip the cache for files with no errors, but in practice that's very rare in real-world projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Potential performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable caching for --fix and --diff ruff much slower with --fix even without lint errors
3 participants