Use a trie-based router to resolve per-file settings#9444
Closed
charliermarsh wants to merge 5 commits intomainfrom
Closed
Use a trie-based router to resolve per-file settings#9444charliermarsh wants to merge 5 commits intomainfrom
charliermarsh wants to merge 5 commits intomainfrom
Conversation
This reverts commit 3c7cbbc.
e3c9a6c to
b54b1c1
Compare
Member
Author
|
Okay, need to fix Windows -- draft for now. |
Member
Author
|
I'm realizing that this likely won't work for paths that contain characters that can be confused for routing characters in matchit (like colons). |
ibraheemdev
added a commit
that referenced
this pull request
Apr 24, 2024
## Summary Continuation of #9444. > When the formatter is fully cached, it turns out we actually spend meaningful time mapping from file to `Settings` (since we use a hierarchical approach to settings). Using `matchit` rather than `BTreeMap` improves fully-cached performance by anywhere from 2-5% depending on the project, and since these are all implementation details of `Resolver`, it's minimally invasive. `matchit` supports escaping routing characters so this change should now be fully compatible. ## Test Plan On my machine I'm seeing a ~3% improvement with this change. ``` hyperfine --warmup 20 -i "./target/release/main format ../airflow" "./target/release/ruff format ../airflow" Benchmark 1: ./target/release/main format ../airflow Time (mean ± σ): 58.1 ms ± 1.4 ms [User: 63.1 ms, System: 66.5 ms] Range (min … max): 56.1 ms … 62.9 ms 49 runs Benchmark 2: ./target/release/ruff format ../airflow Time (mean ± σ): 56.6 ms ± 1.5 ms [User: 57.8 ms, System: 67.7 ms] Range (min … max): 54.1 ms … 63.0 ms 51 runs Summary ./target/release/ruff format ../airflow ran 1.03 ± 0.04 times faster than ./target/release/main format ../airflow ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a small change that I put together a while ago but forgot to clean up. When the formatter is fully cached, it turns out we actually spend meaningful time mapping from file to
Settings(since we use a hierarchical approach to settings). Usingmatchitrather thanBTreeMapimproves fully-cached performance by anywhere from 2-5% depending on the project, and since these are all implementation details ofResolver, it's minimally invasive.We don't need all the behavior of
matchit, but I tried other libraries likeradix_trieand didn't see any speedup vs.main, whereasmatchitshows a consistent improvement.Test Plan