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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bokeh blur cache optimization #1113

Merged
merged 5 commits into from Feb 18, 2020

Conversation

Sergio0694
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 馃懏.
  • I have provided test coverage for my change (where applicable)

Description

The previous implementation of the BokehBlurProcessor<TPixel> was using a static ConcurrentDictionary<BokehBlurParameters, BokehBlurKernelData> field to store the preprocessed bokeh blur kernels for a pair of input parameters. The issue was that that static field was inside a generic class, meaning each concrete <TPixel> instantiation would've seen a completely different dictionary. As a result, running the same bokeh blur effect on multiple images of different pixel formats, even with the same parameters, would've caused the kernels to be recomputed every time, and stored separately in each dictionary, despite the kernels actually being exactly the same (they're not dependent on the pixel type they'll be used on).

This PR moves all the kernel preprocessing logic into a separate non-generic class, to solve the issues described above. I've also removed some unnecessary fields from the BokehBlurProcessor<TPixel> class, so that should also save a few bytes every time a new processor instance is created. 馃殌

@codecov
Copy link

codecov bot commented Feb 14, 2020

Codecov Report

Merging #1113 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1113      +/-   ##
==========================================
+ Coverage      82%   82.02%   +0.01%     
==========================================
  Files         700      701       +1     
  Lines       28797    28797              
  Branches     3281     3281              
==========================================
+ Hits        23616    23621       +5     
+ Misses       4498     4494       -4     
+ Partials      683      682       -1
Flag Coverage 螖
#unittests 82.02% <100%> (+0.01%) 猬嗭笍
Impacted Files Coverage 螖
...sors/Convolution/Parameters/BokehBlurKernelData.cs 100% <酶> (酶) 猬嗭笍
...volution/Parameters/BokehBlurKernelDataProvider.cs 100% <100%> (酶)
...ocessors/Convolution/BokehBlurProcessor{TPixel}.cs 99.03% <100%> (+1.96%) 猬嗭笍

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 f975498...7c02cc4. Read the comment docs.

@JimBobSquarePants JimBobSquarePants merged commit dfa34e9 into master Feb 18, 2020
ImageSharp automation moved this from To Do to Done Feb 18, 2020
@JimBobSquarePants JimBobSquarePants deleted the sp/bokeh-blur-cache-optimization branch February 18, 2020 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
ImageSharp
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants