Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain decorators perform extremely slow function inspection every call #2094

Open
bzczb opened this issue Jan 13, 2024 · 2 comments · May be fixed by #2095
Open

Certain decorators perform extremely slow function inspection every call #2094

bzczb opened this issue Jan 13, 2024 · 2 comments · May be fixed by #2095
Labels
bug Issues that report (apparent) bugs. performance Speed/performance of code or individual functionality.

Comments

@bzczb
Copy link

bzczb commented Jan 13, 2024

In decorators.py, preprocess_args() and use_clip_fps_by_default() do function inspection on their decorated function every time the wrapped function is called. This causes extreme performance issues. On my system a large majority of the time rendering audio, something like 70% or 80%, is spent runninginspect.getfullargspec() on the same functions.

Expected Behavior

The decorators only compute their wrapped function's arguments once.

Actual Behavior

The decorators compute their wrapped function's arguments every time the wrapped function is called.

Steps to Reproduce the Problem

In a Python debugger, render anything in MoviePy. Set a breakpoint inside the decorator wrappers and observe.

Specifications

  • Python Version: 3.12
  • MoviePy Version: master (2.0.0.dev2)
  • Platform: Windows 10
@bzczb bzczb added the bug Issues that report (apparent) bugs. label Jan 13, 2024
@bzczb bzczb linked a pull request Jan 13, 2024 that will close this issue
@keikoro keikoro added the performance Speed/performance of code or individual functionality. label Feb 10, 2024
@Zulko
Copy link
Owner

Zulko commented Nov 24, 2024

Can you share code to reproduce the effect? If I only run a basic example like this one (clip.mp4 is the 30-second big buck bunny clip from medias/):

%%snakeviz
import moviepy as mp
clip = mp.VideoFileClip("clip.webm")
clip.write_videofile("output.mp4")

I get the following profile, where ~90% of the time is spent waiting for ffmpeg to encode the video. Yes 20 seconds to encode a 30-second clip is slow, but only a very small part of that is decorator inspection:

image

For audio-only I also get ~90% spent in IO with ffmpeg:

%%snakeviz
import moviepy as mp
clip = mp.VideoFileClip("clip.webm")
clip.audio.with_speed_scaled(0.2).write_audiofile("output.mp3")

image

@bzczb
Copy link
Author

bzczb commented Nov 24, 2024

Upon testing with the latest moviepy from pypi I too can't reproduce the performance problems, with either Python 3.10 or 3.12.

That example would have been good enough to reproduce, a plain reencode with no effects was making enough audio-related get_frame() calls to get bogged down with function inspection.

However I'm running on OS X now and don't have easy access to a Windows box. Maybe it's still a problem on Windows, or maybe something peculiar to my setup on that machine was making function inspection very expensive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs. performance Speed/performance of code or individual functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants