[WIP] Add optional ImageData argument to getImageData #4748
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.
Optional argument, if provided, will be used instead of creating a new ImageData object. This avoids creating a large amount of unnecessary garbage when getting image data from a canvas at a high frequency.
See #3802 for original discussion and my comment #3802 (comment) for more in-depth discussion on why this change is beneficial. The TL;DR is simple: using
getImageData
to process video data being written to acanvas
creates a large amount of garbage when trying to process at any reasonable FPS, and garbage collection does not handle this well, instead lots of CPU is burned and memory usage is highly variable. Reusing a singleImageData
for frame data eliminates this issue. It's an easy performance win.Creating a PR for this for higher visibility, because the issue wasn't going anywhere and wasn't going to be getting a response.
(See WHATWG Working Mode: Changes for more details.)
/canvas.html ( diff )