-
-
Notifications
You must be signed in to change notification settings - Fork 888
Limit ResizeProcessor memory consumption #888
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
which has been renamed from CalculateResizeWorkerWindowCount()
Codecov Report
@@ Coverage Diff @@
## master #888 +/- ##
==========================================
+ Coverage 88.98% 89.02% +0.04%
==========================================
Files 1018 1024 +6
Lines 44537 44786 +249
Branches 3220 3230 +10
==========================================
+ Hits 39632 39872 +240
- Misses 4194 4202 +8
- Partials 711 712 +1
Continue to review full report at Codecov.
|
This was referenced Apr 26, 2019
antonfirsov
added a commit
to antonfirsov/ImageSharp
that referenced
this pull request
Nov 11, 2019
Limit ResizeProcessor memory consumption
This was referenced Jul 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This PR fixes #642 by limiting the memory consumption of
ResizeProcessorto a value defined inConfiguration.WorkingBufferSizeHintInBytes. Instead of allocating the whole first pass buffer, a sliding window is implemented byResizeWorker<T>. The height of the window is a multiple of the vertical kernel's maximum diameter depending onConfiguration.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:
Results
There is no regression in speed. (Actually, we are faster now for .NET 4.72 than before.)
The resizing of a
4000 x 4000image to300 x 300has been memory profiled using JetBrains dotMemory. The resize operation has been executed 50 times in a single process.Memory profile before the optimization
Timeline:


Typical snapshot:

Memory profile after the optimization
Timeline:

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