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

Watermark plugin should request overlay image bytestreams prior to the load stage for the main image #69

Closed
lilith opened this issue Nov 27, 2013 · 3 comments
Assignees
Milestone

Comments

@lilith
Copy link
Member

lilith commented Nov 27, 2013

The logic is thus:

  1. Overlays tend to be smaller than primary images
  2. Network/disk latency can cause image processing to 'pause' during a render stage, which is catastrophic to RAM use, as 200MB block of RAM may be held open for 1-10s instead of 200ms.
  3. If we have a MemoryStream of overlay images before the primary image is even decoded, we theoretically limit the render phase time to 20% overhead (overlay jpeg decoding). Locking on a cached Bitmap instance is OK, as all DrawImage calls are serialized anyway. It doesn't address initial latency problems though, which can be bad during startup for concurrent similar requests.
@ghost ghost assigned JaredReisinger Nov 27, 2013
@JaredReisinger
Copy link
Contributor

In the GDI+ pipeline, the source image is loaded very early... ImageBuilder.LoadImage() is called at the top of ImageBuilder.BuildJob(). We might be able to co-opt AbstractImageProcessor.PreLoadImage(), but the obvious place to stash the watermark images, ImageState.Data, doesn't exist yet. (It doesn't get created until ImageBuilder.buildToBitmap().)

Rather than using ImageState.Data, or changing the signature for PreLoadImage(), the watermark plugin itself could cache the watermark images, which might also allow them to stay in memory across multiple ImageBuilder.Process() calls. Does that seem reasonable? I'm starting with this as the design, but wanted to bounce the idea off of you in case there were specific multi-threading/contention issues that would need to be worked around, or if there is a better place to stash the watermark images between load and render.

@JaredReisinger
Copy link
Contributor

It looks like watermark Bitmaps are already getting cached by the ASP.NET cache, when it's available. Can we simply rely on this for the pre-fetch as well? We can call GetMemCachedBitmap() purely for the side-effect of ensuring the image is in the cache before the Render call.

I'm not sure in what cases HttpContext.Current would be null in practice, but leveraging GetMemCachedBitmap() would be much simpler than adding caching to ImageLayer or the Watermark plugin itself, and automatically handles aging out cached watermarks after a period of time.

@lilith
Copy link
Member Author

lilith commented Dec 17, 2013

Yes, that's fine - we're already making the assumption that watermarks remain in memory - this would just make that usage more effective. In a later version I'd prefer to cache only the bytestream or immutable decoded bitmap, but this is easier for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants