Skip to content

Limit ResizeProcessor memory consumption - #888

Merged
antonfirsov merged 40 commits into
masterfrom
af/resize-sandbox
Apr 22, 2019
Merged

antonfirsov merged 40 commits into
masterfrom
af/resize-sandbox

Conversation

@antonfirsov

@antonfirsov antonfirsov commented Apr 20, 2019 •

Copy link
Copy Markdown
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

This PR fixes #642 by limiting the memory consumption of ResizeProcessor to a value defined in Configuration.WorkingBufferSizeHintInBytes. Instead of allocating the whole first pass buffer, a sliding window is implemented by ResizeWorker<T>. The height of the window is a multiple of the vertical kernel's maximum diameter depending on Configuration.WorkingBufferSizeHintInBytes.

The implementation is most likely very different from MagicScaler's one (haven't seen it's code). It was a goal to keep the changes under control, the new code is basically a refactor of the old one.

The optimization is visually explained in ResizeWorker.pptx:

image

image

image

Results

There is no regression in speed. (Actually, we are faster now for .NET 4.72 than before.)

The resizing of a 4000 x 4000 image to 300 x 300 has been memory profiled using JetBrains dotMemory. The resize operation has been executed 50 times in a single process.

Memory profile before the optimization

Timeline:
image
image

Typical snapshot:
image

Memory profile after the optimization

Timeline:
image

image

(The second peak has been only triggered because I made the snapshot. Can anyone explain this?)

Typical snapshot:
image

@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Apr 22, 2019
@antonfirsov
antonfirsov merged commit 87c0a66 into master Apr 22, 2019
@JimBobSquarePants
JimBobSquarePants deleted the af/resize-sandbox branch April 23, 2019 04:19
antonfirsov added a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
Limit ResizeProcessor memory consumption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize memory consumption of ResizeProcessor

3 participants