W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2009

[whatwg] Canvas pixel manipulation and performance

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Sun, 29 Nov 2009 15:03:53 -0500
Message-ID: <4B12D3A9.5040607@mit.edu>
On 11/29/09 1:20 PM, Jason Oster wrote:
>>> Changeset 2b56c4771d5c reduced the number of pixel array elements
>>> accessed by caching the 256px x 256px "rooms" within the stage map, and
>>> passing the cached rooms to putImageData().
>>
>> As opposed to doing what before the change?
> The previous code used a "non-cached" approach.  Where every pixel in the canvas was explicitly drawn into the ImageData array.  Keep in mind, the largest of these was 4864px ? 3072px.  If anything, the change took time away from JavaScript and placed it in native code: putImageData().

I'm not sure I follow.  Looking at the diff, it looks like you used to 
do a single putImageData call, passing it this.fgmap.render(), right?

Now you do a bunch of putImageData calls, passing 
this.fgmap[rooms[i++]].img, where right before that you called 
this.fgmap[i].render() for a bunch if "i".

I really don't see how this would have made things faster, unless 
render() is just not being called on all rooms now.

-Boris
Received on Sunday, 29 November 2009 12:03:53 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:19 UTC