# Path format performance

**URL:** <https://discourse.beets.io/t/path-format-performance/1908>\
**Category:** Help\
**Created:** [October 20, 2021, 6:12pm UTC](https://discourse.beets.io/t/path-format-performance/1908 "2021-10-20T18:12:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kergoth](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/kergoth/32/240_2.png) [@kergoth](https://discourse.beets.io/u/kergoth)\
**Post date:** [October 20, 2021, 6:12pm UTC](https://discourse.beets.io/t/path-format-performance/1908/1 "2021-10-20T18:12:26Z")

</div>

Hey all,

I’m having an issue with the performance of the path formats I’m using with the beets-alternatives plugin. Updating the alternative is incredibly slow (literally 2-3 seconds per track!). Admittedly, it’s a complex set of formats, with many queries and multiple plugins involved adding fields and functions, so the root cause could be almost anything, or just the accumulation of time due to the indirections I added to attempt to make it easier to maintain the formats.

I’m wondering if implementing all the logic in a smaller set of python functions and doing less in path formats and through field indirections would be my next best step, if there’s no good benchmarking options.

Most likely it’s one of my plugins or the number of indirections in order to make it readable that are causing the problems, but I’m wondering if we have any mechanisms for benchmarking of path format processing?

Thanks.

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [October 21, 2021, 11:24am UTC](https://discourse.beets.io/t/path-format-performance/1908/2 "2021-10-21T11:24:42Z")

</div>

Very interesting! It would be fascinating to know exactly where the time is being spent… any interest in trying to run a Python profiler (like [cProfile](https://docs.python.org/3/library/profile.html)) that should be able to detect exactly where in the code is being slow? That might lead to suggestions about what to change to avoid the bottleneck.

---

<div class="post-metadata">

**Author:** ![RollingStar](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/rollingstar/32/728_2.png) [@RollingStar](https://discourse.beets.io/u/RollingStar)\
**Post date:** [October 24, 2021, 5:55pm UTC](https://discourse.beets.io/t/path-format-performance/1908/3 "2021-10-24T17:55:17Z")

</div>

I did some non scientific tests. Path formats indeed ate up performance.

> [@Time to rethink path formats?](https://discourse.beets.io/t/time-to-rethink-path-formats/1402/5):
>
> I tested it and feel good. Need to do more tests. I have a few hundred imports coming eventually™ and it should be a good chance to torture test this concept. After this initial test, I feel better about Python/some other system and worse about the current setup. However, forcing users to do it manually is a no-go, if my experience is an indication. pros incredibly readable: I can set up my paths like a regular python script and loosely follow PEP8 Python engineering is available. I can autofo…

I have a very precise renaming scheme that relied heavily on regex. Moving it over to python made it “conservatively, 2x faster” on my machine. You can see the code before and after at the link.

> i’ve moved all my album fields to a single python inline call. is there something about `inline` that might cause poor performance invoking 10ish functions? 8ish of them are very basic 5 line string manipulation functions. is `compile_inline` the culprit? Edit: Or maybe commenting out `aunique` does it? Or the regex in the path formats?

Related (can also search github/here for ‘performance’, ‘path format’ etc)

> [@Beets as a use case for (master) thesis](https://discourse.beets.io/t/beets-as-a-use-case-for-master-thesis/1421/):
>
> Hi, I’m in the process of choosing a project for my masters thesis (computer science + engineering). I have been using beets for a while and now I’m playing with the idea of beets as a use case for my thesis. The motivation being to contribute to beets in some way. I have some ideas as to what I could do. However, before I get too carried away, I would love to get some feedback from those involved: do you find beets as a suitable use case (research-able)? With the open nature of the project, …

---

<div class="post-metadata">

**Author:** ![kergoth](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/kergoth/32/240_2.png) [@kergoth](https://discourse.beets.io/u/kergoth)\
**Post date:** [October 30, 2021, 12:42am UTC](https://discourse.beets.io/t/path-format-performance/1908/4 "2021-10-30T00:42:02Z")

</div>

Thanks, indeed, shifting everything into functions in a plugin _massively_ improved performance.
