You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Regression] New multithreaded reformat function slower by default than with just 1 thread used in PyAV < 17.0.0 #2200
In the latest version, to_ndarray(format='rgb24') is significantly slower by default. Forcing threads=1 restores the original performance inline with PyAV 16.1.0. Seems to only occur consistently on unique video frames, hence the startup code in the script underneath. I expected a performance increase from this new update. :-) @lgeiger I hope its fine if I tag you here - you added this new functionality which is really appreciated and you might know whats going on here. :-)
I dont have a mac so I cant test there aswell. @WyattBlue I have not tested on 3.14t but I think something else is going on here. On Linux and Windows its considerably slower.
Edit: FYI: I've noticed this in my program that makes use of PyAV where the whole runtime in my testcase increased from 42 seconds to over 60 seconds after upgrading to PyAV 17.0.0.
I'm not sure why the single threaded run with a shared reformatter is slower 🤔 Maybe this is an artefact from the benchmarking?
Looks like this is indeed just an artefact of the test ordering. So there's no regression when running single threaded with a shared reformatter.
Looking into this a bit closer, it seems like setting up a thread pool on macOS has much lower overhead than on Linux or Windows. This causes .to_ndarray(threads=0) to be much slower since it sets up a new threadpool on each call.
I guess using threads=1, at least for Linux/Windows, is a more sensible behaviour. We could think about keeping threads=0 as the default for the reformatter since it's might be reused multiple times, but that seems a bit inconsistent.
@WyattBlue Do you prefer switching back to threads=1 for all platforms or do you prefer keeping threads=0 for macOS? I think I'd slightly favour sticking with threads=1 for all platforms. Users can then still tune this manually for their specific workload.
We can't release until like July 1st (storage limitations). Given that it's very likely that upstream will, or has already, fixed this issue on their end (by making threads faster or something), we should just tell users to set threads and leave it at that.
Just for future reference and people maybe stumbling over this.
This issue is resolved with version 19.0.x and later. Here I can see a speedup >2x on my Windows system now with the original example I posted when I opened this issue. I assume the fix was #2379.
Activity
WyattBlue commentedon Mar 16, 2026
You might be just be measuring 3.11 limited api perf regression, which is known issue. You should try using 3.14t
lgeiger commentedon Mar 16, 2026
I can't seem to reproduce this regression on my machine. I'm using the wheel from pypi with 3.12.13 on macOS:
@timminator Maybe this is an issue related to Windows? Can you also reproduce this on Linux?
timminator commentedon Mar 16, 2026
Thanks for the quick replies!
@lgeiger Yes, im also seeing this on Linux:
I dont have a mac so I cant test there aswell.
@WyattBlue I have not tested on 3.14t but I think something else is going on here. On Linux and Windows its considerably slower.
Edit: FYI: I've noticed this in my program that makes use of PyAV where the whole runtime in my testcase increased from 42 seconds to over 60 seconds after upgrading to PyAV 17.0.0.
timminator commentedon Mar 16, 2026
I was able to test 3.14t on another Windows install with the same result:
So something is not correctly working on Windows and Linux.
lgeiger commentedon Mar 16, 2026
Thanks for testing. I also ran the above benchmark on Linux:
CPU: AMD EPYC 9R45
OS: Ubuntu 24.04.3 LTS
Python: Python 3.12.3
And I'm also not seeing any benefits from multithreading, although there is no regression:
Though it seems like I'm when I'm reusing the same reformatter I am seeing benefits from multithreading:
I'm not sure why the single threaded run with a shared reformatter is slower 🤔 Maybe this is an artefact from the benchmarking? @WyattBlue any ideas?
WyattBlue commentedon Mar 16, 2026
My results on AArch64 MacOS:
lgeiger commentedon Mar 17, 2026
Looks like this is indeed just an artefact of the test ordering. So there's no regression when running single threaded with a shared reformatter.
Looking into this a bit closer, it seems like setting up a thread pool on macOS has much lower overhead than on Linux or Windows. This causes
.to_ndarray(threads=0)to be much slower since it sets up a new threadpool on each call.I guess using
threads=1, at least for Linux/Windows, is a more sensible behaviour. We could think about keepingthreads=0as the default for the reformatter since it's might be reused multiple times, but that seems a bit inconsistent.@WyattBlue Do you prefer switching back to
threads=1for all platforms or do you prefer keepingthreads=0for macOS? I think I'd slightly favour sticking withthreads=1for all platforms. Users can then still tune this manually for their specific workload.WyattBlue commentedon Mar 17, 2026
We can't release until like July 1st (storage limitations). Given that it's very likely that upstream will, or has already, fixed this issue on their end (by making threads faster or something), we should just tell users to set
threadsand leave it at that.(We really need to benchmark 480p to 4k anyway)
timminator commentedon Oct 5, 2026
Just for future reference and people maybe stumbling over this.
This issue is resolved with version 19.0.x and later. Here I can see a speedup >2x on my Windows system now with the original example I posted when I opened this issue. I assume the fix was #2379.