-
-
Notifications
You must be signed in to change notification settings - Fork 888
Closed
Labels
Milestone
Description
Problem
- In some use cases the default
ArrayPoolbehavior does not fit user needs (see Encoding an animated image requires all frames to be loaded into memory, can lead to OutOfMemoryExceptions #222). Users should be able to configure + reset + disable pools. - Some users may want to back
Image<T>by memory resources other than managed memory. (Eg. native buffers).
Solution
Implement a pluggable MemoryManager, make the default pooling memory manager configurable.
Update:
feature/memory-manager is the WIP branch for this refactor. It's having #431 merged. If anyone wishes to contribute, please file your PR-s against that branch. The tasks below are being updated according to the progress on that branch.
Tasks for beta-3
- Refactor all raw
ArrayPoolandPixelDataPoolusages to useBufferandBuffer2Dinstead. -
Buffer2D<T>should composeBuffer<T>(asIBuffer<T>) instead of inheriting it - Move the responsibility of providing
Buffer<T>instances to a generic MemoryManager class. Refactor allnew Buffer<T>andnew Buffer2D<T>instantiations to call factory method onMemoryManagerinstead. - We need to cover all the encoders/decoders with proper regression tests before continuing the refactor work. (Working on this - would be filed as a separate PR)
- Extensive test coverage for
ArrayPoolMemoryManager - Allocations in
DefaultPixelBlenders<TPixel>should useMemoryManagertaken from the outside - Replace the legacy
PixelArea<TPixel>class withBufferArea<T>+ extensions methods working onBufferArea<TPIxel>and/orIBuffer2D<TPixel>usingPixelOperations<TPixel> - Replace
allmostPixelAccessor<TPixel>usages withBuffer2D<T>.Drop the- the full removal could be done later.IBuffer2D<T>interface. -
MemoryManagershould constructIBuffer<T>andIManagedByteBufferinstead ofBuffer<T>, codecs should useIManagedByteBuffer.Array - Based on user feedback, there also might be some strange, unexpected leaking when images are created/destroyed continously. Doing some load testing, identifying+understanding this behavior is inevitable!
Probably 1.0
- Passing custom
MemoryManagerto codecs
Most likely post- 1.0:
- Passing custom
MemoryManagertoMutate()andClone()(---> Allow passing custom Configuration instances to processors #650) - Investigate new
System.MemoryAPI-s:Memory<T>and
OwnedMemory<T>. Find a way to integrate these classes intoImageSharp.Memory. -
Image.Wrap<T>(Memory<T> memory)or similar - Implement an
MMFMemoryManagerwhich uses Memory Mapped Files to reduce the pressure on system memory when processing large images.