Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

canvas caching/pooling #14

Closed
jakrzysztow opened this issue Aug 13, 2015 · 5 comments
Closed

canvas caching/pooling #14

jakrzysztow opened this issue Aug 13, 2015 · 5 comments
Assignees

Comments

@jakrzysztow
Copy link

We use watermarkjs in an application have found that canvases to not get garbage collected in IE. For other places in the system that are using canvases, we implemented a pooling system to reuse canvases.

Would like to know how to get watermarkjs to either do its own canvas pooling or how to add what we are doing and have one shared canvas pool.

@brianium
Copy link
Owner

This request seems reasonable. Currently, a new canvas is created every time a watermark object calls dataUrl (by calling imageToCanvas from the image module). The proposal would be instead of creating one, pull from a pool correct?

I will take a look into this. The shared state of a pool provides some challenges for a functional style library, but I have seen similar scenarios overcome through the use of actors/signals in other languages.

Bottom line: I hear you, and I will investigate. Might take some time to come up with an elegant solution though.

Thank you for opening the issue :)

@jakrzysztow
Copy link
Author

I was able to figure out when/where the canvas is created, but not a clear idea how to pool canvases because I couldn't really figure out how to reclaim them to the pool.

Basically, processing a lot of images creates a lot of canvases and IE is just extremely unhappy.

You are welcome!

@brianium brianium self-assigned this Dec 27, 2015
@brianium
Copy link
Owner

brianium commented Jan 1, 2016

@jakrzysztow sorry for the wait, I'm hoping you can take a peak at the work towards implementing the pool feature.

I have a pull request here: #17

Files of interest might be the pool implementation, and its use in the main export

watermark.js essentially reuses a canvas if available, or creates a new one, which in turn can be reused. This drastically limits the canvases created, but I was a little uncertain on an ideal "done" scenario, hence the watermark.destroy function, which explicitly clears the pool's canvas elements.

@brianium
Copy link
Owner

Merged into master - will tag a new version with these changes

@jakrzysztow
Copy link
Author

Sorry to say I will have no way to test this as we no longer work on the project. I appreciate your work!

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

No branches or pull requests

2 participants