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

ruff much slower with --fix even without lint errors #8311

Closed
lukaspiatkowski opened this issue Oct 28, 2023 · 1 comment · Fixed by #8316
Closed

ruff much slower with --fix even without lint errors #8311

lukaspiatkowski opened this issue Oct 28, 2023 · 1 comment · Fixed by #8316
Assignees
Labels
performance Potential performance improvement

Comments

@lukaspiatkowski
Copy link
Contributor

When I call ruff . it finished in 0.15s on my repo, but ruff --fix . takes >2.5s, even if there are no lint errors and nothing to fix. Is it safe to always call ruff . and run it again with --fix only when the are some fixable issues? If so then maybe there is some room for improvement in ruff itself?

My use case was that we have replaced isort (and few other tools) with ruff --fix and it is much faster, but I was looking into speeding it up even more. We run black && ruff --fix, black takes 0.8s and I hoped to speed it up with ruff format, but then noticed that ruff --fix takes most of the execution time.

@charliermarsh
Copy link
Member

Let me look into this… I think we might be intentionally skipping the cache when the linter is run with the fix flag, but that may no longer be necessary for a variety of reasons. At least, I don’t see an inherent reason why we need to skip the cache any more.

But yes — you can always run ruff with fix after running ruff, only if there are any fixable issues.

@charliermarsh charliermarsh self-assigned this Oct 28, 2023
@charliermarsh charliermarsh added the performance Potential performance improvement label Oct 28, 2023
charliermarsh added a commit that referenced this issue Oct 29, 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.
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 a pull request may close this issue.

2 participants