diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2020-12-15 12:45:13 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2020-12-15 14:16:09 +0100 |
commit | 3fec6d347a432e34adc9d74e87ff465107da74b7 (patch) | |
tree | 24926ae06a383f08900a96d9661c681a41e894a6 | |
parent | 8645f56512fa8918fd05c4f53bd1b65ace87ab41 (diff) |
Use caching in plugins.find_plugins()sam/fast-plugin-setup
This function is called from library.Item._getters(), making it a hot
path when exporting data. We cache plugin instances but previously we
reran `import` for each module on each call. We now return the cached
values providing a speed boost for `beet export`.
This has a small effect on `beet ls` speed: for me it went 11.00s ->
10.40.
It had a significant effect on `beet export` speed when combined with
https://github.com/beetbox/beets/pull/3762/.
Before:
$ time /home/sam/.local/bin/beet 'export' '--library' '--format' 'jsonlines' '--include-keys' 'artist,title,path,mb_artistid,mb_trackid' 'artist+ title+' > /dev/null
Executed in 25.13 secs
After:
$ time /home/sam/.local/bin/beet 'export' '--library' '--format' 'jsonlines' '--include-keys' 'artist,title,path,mb_artistid,mb_trackid' 'artist+ title+' > /dev/null
Executed in 10.49 secs
-rw-r--r-- | beets/plugins.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/beets/plugins.py b/beets/plugins.py index 695725cb8..3abd911c9 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -301,6 +301,11 @@ def find_plugins(): currently loaded beets plugins. Loads the default plugin set first. """ + if _instances: + # After the first call, use cached instances for performance reasons. + # See https://github.com/beetbox/beets/pull/3810 + return list(_instances.values()) + load_plugins() plugins = [] for cls in _classes: |