[whatwg] Canvas performance issue: setting colors

Ian Hickson ian at hixie.ch
Thu Apr 30 15:44:41 PDT 2009


On Tue, 30 Sep 2008, Sjoerd Visscher wrote:
> 
> I think the canvas api should get 2 new methods:
> 
>   CanvasColor createRGBAColor(in float r, in float g, in float b, in float a)
>   CanvasColor createHSLAColor(in float h, in float s, in float l, in float a)

On Mon, 29 Sep 2008, Oliver Hunt wrote:
> 
> WebKit already has a non-standard function -- setFillColor(r, g, b, a) 
> -- that provides a faster mechanism to set the colour, however we 
> believe we can rather easily improve the performance of the standard 
> fillStyle, strokeStyle properties and just have not yet gotten round to 
> it.  Until we have improved this I would be hesitant to go around adding 
> entirely new object types (especially canvas specific ones).

On Sat, 4 Oct 2008, Oliver Hunt wrote:
> 
> Ah, I was not meaning to in any way suggest that we change the type of
> fillStyle/strokeStyle, merely to overload the assignment behaviour to allow
> arrays to be used -- although i'm not sure whether there is a clean way to
> represent this in the idl definitions in the spec.
> 
> Basically i would expect
> context.fillStyle = [1,1,1,0.5]
> alert(context.fillStyle);
> to produce an output akin to rgba(255,255,255,0.5) or some such.

On Sat, 4 Oct 2008, Maciej Stachowiak wrote:
> 
> We could also consider letting fillStyle take a number to be interpreted 
> as a 32-bit RGBA value, since modern JS engines can do math and masking 
> faster than string operations or array allocation. But the broken out 
> setFillStyle version seems like it might still be more of a perf win in 
> many cases.

As noted here:

   http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-April/019503.html

I've taken note of the idea of setting colours by component for a future 
version, but I haven't added it to the spec yet. I think we will probably 
want to support either a direct setter, an array setter, or a 32bit int 
setter at some point, though.

Having said that, color strings are pretty short... can much mileage be 
gotten out of atomising them and keeping a mapping of string to color? It 
seems that that could be done pretty efficiently.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list