Speed up plugin discovery - #2194
Draft
JeanChristopheMorinPerso wants to merge 1 commit into
Draft
Conversation
Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a0771d-16ef-7787-b60b-eb71b1cc8a4b Co-authored-by: Amp <amp@ampcode.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2194 +/- ##
==========================================
+ Coverage 61.29% 61.44% +0.14%
==========================================
Files 164 164
Lines 20568 20629 +61
Branches 3575 3591 +16
==========================================
+ Hits 12607 12675 +68
+ Misses 7089 7084 -5
+ Partials 872 870 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def _get_entry_points(_cache_key): |
Member
Author
There was a problem hiding this comment.
This is such a weird pattern. I'll have to rewrite this into something that looks more sane.
| T = TypeVar("T") | ||
|
|
||
|
|
||
| def _entry_points_cache_key(): |
Member
Author
There was a problem hiding this comment.
Same here, weird pattern.
| _get_entry_points.cache_clear() | ||
|
|
||
|
|
||
| def _iter_top_level_modules(): |
Member
Author
There was a problem hiding this comment.
I have to review the correctness of this function.
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.
Leaving as draft until I get the time to polish and fully review the tests and think about potential unexpected side effects.
Summary
Plugin discovery was spending a surprising amount of time repeatedly scanning Python packages, installed entry-point metadata, and shared plugin configuration.
This changes the discovery path in three places:
os.scandir()fast path when looking for top-level packages that may containrezplugins.sys.pathor its directory mtimes change.rezconfigonce per plugin directory instead of once per plugin module.ZIP files and custom importers still fall back to
pkgutil, so those discovery mechanisms continue to work as before.Performance
The benchmark repeatedly resets and loads all seven plugin types for 100 discovery cycles. It excludes the unrelated import optimizations investigated earlier.
rezpluginsdiscoveryThe individual timings are cumulative
cProfileresults over the repeated workload run using hyperfine, so they are not intended to add up to thehyperfinewall-clock result.Testing
sys.pathchanges.pkgutil.iter_modules()in the benchmark environment.AI usage
This was mostly generated by an LLM with a lot of babysitting.
Amp-Thread-ID: https://ampcode.com/threads/T-01a0771d-16ef-7787-b60b-eb71b1cc8a4b (sorry in advanced for cursing a bit in that thread... The models were gaslighting me in multiple threads all trying to inline dozens of imports to find performance gains).