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

Optimized, parallelized Blur effect #423

Merged
merged 2 commits into from Feb 27, 2020

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Feb 3, 2020

This PR optimizes the Blur effect (by far our slowest effect), streamlining the code and (most importantly) adding OMP #pragmas to multi-thread the execution where the operations can be cleanly parallelized.

It still won't win any speed trophies (in fact, it's still slow as fuck), but testing on my 4-core Intel i5 system, during an export of an 11-second Big Buck Bunny clip with a default-settings Blur applied:

  • CPU usage went up from 25% to 85%-95%
  • Export rate estimation increased from 0.57 FPS to > 1.2 FPS, making the new code more than twice as fast
  • I don't know what the full export time would have been for the old code because I gave up and canceled after 2 minutes when it was only at 20%. But with the new code, the full export completed in 4m37s — so, again, more than twice as fast.
  • Results appear identical, at least to my eye.

I took a second run at this, after re-re-rereading the OpenMP docs, and improved the parallelization significantly. Now, exporting a slightly different clip than my previous tests, the results
on my 4-core Intel Core i5 system are:

  • CPU usage went up from 25% to around 85%
  • Export rate estimate increased from 0.58 FPS to over 5.1 FPS, making the new code nearly 10x as fast
  • The old export would've taken about 13 minutes to complete (again, I aborted before it finished), whereas the new code can export the same thing in 1m 28s
  • The results are identical; a video diff of the two exports produces a solid gray field (no differences)
  • Unlike my previous attempt, I expect the new code now will benefit from additional cores, and run even faster

Note

You may notice that in my new code, I don't use initBoxes, and the sigma property does nothing. In fact, I removed the initBoxes function (and all references to it) completely.

The reason for this is simple: In the current (old) Blur effect, the results of initBoxes are never used, and the sigma property does nothing.

I don't know if that was intentional or a bug, but in the existing Blur code, initBoxes() is a useless function — even though it's called, the results are never used in the code. So as things stood, there was no point in having it in the code. Which is why I removed it.

@codecov-io
Copy link

codecov-io commented Feb 3, 2020

Codecov Report

Merging #423 into develop will decrease coverage by 0.24%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #423      +/-   ##
===========================================
- Coverage    42.37%   42.13%   -0.25%     
===========================================
  Files          129      129              
  Lines        13276    13220      -56     
===========================================
- Hits          5626     5570      -56     
  Misses        7650     7650
Impacted Files Coverage Δ
include/effects/Blur.h 100% <ø> (ø) ⬆️
src/effects/Blur.cpp 59.32% <100%> (-13.1%) ⬇️

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 49972b2...fd663c4. Read the comment docs.

src/effects/Blur.cpp Outdated Show resolved Hide resolved
@ferdnyc ferdnyc changed the title Optimized, parallelized Blur effect WIP: Optimized, parallelized Blur effect Feb 5, 2020
@ferdnyc ferdnyc changed the title WIP: Optimized, parallelized Blur effect Optimized, parallelized Blur effect Feb 6, 2020
@jonoomph
Copy link
Member

Awesome job! LGTM

@jonoomph jonoomph merged commit 6666702 into OpenShot:develop Feb 27, 2020
@ferdnyc ferdnyc mentioned this pull request Mar 12, 2020
@ferdnyc ferdnyc deleted the optimized-blur branch March 12, 2020 18:10
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.

None yet

3 participants