Skip to content

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

Merged
charliermarsh merged 1 commit intomainfrom
charlie/cache
Oct 29, 2023
Merged

Allow selective caching for --fix and --diff#8316
charliermarsh merged 1 commit intomainfrom
charlie/cache

Conversation

@charliermarsh
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@charliermarsh charliermarsh deleted the charlie/cache branch October 29, 2023 16:06
@lukaspiatkowski
Copy link
Copy Markdown
Contributor

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

@charliermarsh
Copy link
Copy Markdown
Member Author

Nice, thanks for testing on main! Appreciate it!

@charliermarsh
Copy link
Copy Markdown
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