Why is putImageData so slow?

后端 未结 4 768
梦谈多话
梦谈多话 2020-11-30 20:07

I am working with a relatively large Canvas where various (complex) stuff is drawn to. I then want to save the Canvas\' state, so I can quickly reset it to the state it now

4条回答
  •  渐次进展
    2020-11-30 21:00

    Firstly you say you are measuring with Firebug. I actually find that Firebug slows down JS execution considerably, so you may not be getting good numbers for performance.

    As for putImageData, I suspect it's because the functions takes a large JS array containing many Number objects, all of which have to be checked for range (0..255) and copied into a native canvas buffer.

    Maybe once the WebGL ByteArray types are available, this sort of thing can be made quicker.

    It does seem odd that base64 decoding and uncompressing the data (with the PNG data URL) is quicker, but that only calls one JS function with one JS string, so it is using mostly native code and types.

提交回复
热议问题