perf(linter): avoid multiple to_string_lossy calls in loop#17212
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the performance of file filtering by eliminating redundant to_string_lossy() calls. Instead of converting the filename to a string up to 3 times within the iterator (once per pattern check), the conversion is now performed once before the loop.
Key changes:
- Extract
to_string_lossy()call outside the.any()iterator to avoid repeated string conversions
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Just for fun, I tried a further optimization, but unclear if it's better or not. Current version is massive amount of code, but looks like it uses SIMD: https://godbolt.org/z/6dx1438Gv |
|
I would hope the compiler just hoists it out of the loop? but i guess not |
Merge activity
|
Small optimization: Call `to_string_lossy` only once, rather than 3 times in a loop.
086c435 to
78df915
Compare
I doubt it. |

Small optimization: Call
to_string_lossyonly once, rather than 3 times in a loop.