Skip to content

perf(linter): avoid multiple to_string_lossy calls in loop#17212

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/12-21-perf_linter_avoid_multiple_to_string_lossy_calls_in_loop
Dec 21, 2025
Merged

perf(linter): avoid multiple to_string_lossy calls in loop#17212
graphite-app[bot] merged 1 commit intomainfrom
om/12-21-perf_linter_avoid_multiple_to_string_lossy_calls_in_loop

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Dec 21, 2025

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

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI labels Dec 21, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Dec 21, 2025
@overlookmotel overlookmotel marked this pull request as ready for review December 21, 2025 16:02
Copilot AI review requested due to automatic review settings December 21, 2025 16:02
@overlookmotel overlookmotel marked this pull request as draft December 21, 2025 16:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@overlookmotel overlookmotel marked this pull request as ready for review December 21, 2025 16:17
@overlookmotel
Copy link
Member Author

overlookmotel commented Dec 21, 2025

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

@camc314
Copy link
Contributor

camc314 commented Dec 21, 2025

I would hope the compiler just hoists it out of the loop? but i guess not

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Dec 21, 2025
Copy link
Contributor

camc314 commented Dec 21, 2025

Merge activity

Small optimization: Call `to_string_lossy` only once, rather than 3 times in a loop.
@graphite-app graphite-app bot force-pushed the om/12-21-perf_linter_avoid_multiple_to_string_lossy_calls_in_loop branch from 086c435 to 78df915 Compare December 21, 2025 16:27
@graphite-app graphite-app bot merged commit 78df915 into main Dec 21, 2025
18 checks passed
@graphite-app graphite-app bot deleted the om/12-21-perf_linter_avoid_multiple_to_string_lossy_calls_in_loop branch December 21, 2025 16:33
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 21, 2025
@overlookmotel
Copy link
Member Author

overlookmotel commented Dec 21, 2025

I would hope the compiler just hoists it out of the loop? but i guess not

I doubt it. string_to_lossy is probably too complicated a function for compiler to reason about. It probably has to assume that it could return a different value each time it's called and therefore hoisting it out of the loop isn't a safe optimization. I could be wrong though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants