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

Huge performance improvements (43% faster FFmpegReader, 34% faster Timeline) #638

Merged
merged 9 commits into from
Feb 25, 2021

Conversation

jonoomph
Copy link
Member

@jonoomph jonoomph commented Feb 18, 2021

After some extensive profiling using a variety of tools, we have found a few interesting and actionable issues. Bottom line, OpenMP is not actually providing us any improvement where we need it, and instead, it's adding additional overhead, by spinning up many threads, waiting for threads to finish, shutting down threads, etc...

Related openshot-qt PR: OpenShot/openshot-qt#4012

Improvements:

  • I've removed OpenMP from Timeline, FFmpegReader classes. These are now optimized to return the first matching frame as quickly as possible (no more attempting to process a bunch of Frame instances in multiple threads).
  • I've refactored Clip::GetFrame, including an override that allows the Timeline to pass in the current Frame (to be used as a background image). This prevents calling QPainter::drawImage multiple times (and saves a bunch of CPU)
  • Reduced some unneeded memory copying and allocating

Testing:

  • I did many tests on many different machines, including A/B testing with the current stable release of OpenShot.
  • I tested on Chromebook, Windows, Mac, and Linux (to verify the performance gains on a variety of different machines, some very powerful, some borderline decent).

… Calling OMP_MP_NUM_PROCESSORS less often, since it's quite expensive according to profiling. Adjusting Timeline final_cache to match the video caching thread max_frames, so one doesn't clobber the other. Also, fixing an issue with openshot-player, where a video file with no audio skips horribly.
…4. Trying to experiment and reduce stuttering.
… on the Timeline and FFmpeg-related classes). The logic behind this decision, was based on profiling libopenshot and the amount of wasted CPU idle time on all the various threads. The slow code is still synchronous, and all the threads must wait on each other, adding additional overhead. So, removing lots of unneeded threads, and simplifying the underlying Timeline->Clip->FFmpegReader flow. Also, removed 2 calls to QPainter::drawImage, by improving the flexibility of Clip->GetFrame.
@codecov
Copy link

codecov bot commented Feb 18, 2021

Codecov Report

Merging #638 (57bc762) into develop (f7472d5) will decrease coverage by 0.31%.
The diff coverage is 76.10%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #638      +/-   ##
===========================================
- Coverage    51.86%   51.54%   -0.32%     
===========================================
  Files          151      151              
  Lines        12334    12228     -106     
===========================================
- Hits          6397     6303      -94     
+ Misses        5937     5925      -12     
Impacted Files Coverage Δ
src/Clip.h 75.00% <0.00%> (ø)
src/ClipBase.h 80.76% <ø> (ø)
src/FFmpegReader.h 66.66% <ø> (ø)
src/KeyFrame.cpp 85.48% <0.00%> (-0.35%) ⬇️
src/Qt/VideoCacheThread.cpp 0.00% <0.00%> (ø)
src/Qt/VideoCacheThread.h 0.00% <ø> (ø)
src/QtPlayer.cpp 0.00% <0.00%> (ø)
src/Settings.cpp 100.00% <ø> (ø)
src/Settings.h 50.00% <ø> (ø)
src/Timeline.h 63.63% <ø> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7472d5...8280e20. Read the comment docs.

@jonoomph
Copy link
Member Author

Merging this one!

@jonoomph jonoomph merged commit 9437727 into develop Feb 25, 2021
@jonoomph jonoomph deleted the profiling-improvements branch February 25, 2021 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant