[webkit-dev] Canvas color CSS parsing performance

Simon Fraser simon.fraser at apple.com
Sun Jan 4 17:03:35 PST 2009


On Jan 4, 2009, at 2:52 PM, Dean McNamee wrote:

> I've been working on some canvas code that is an animation doing many
> fills of different colors.  I've spent some time profiling my code,
> and the majority of time (over 8%) spent in WebKit is in the CSS
> parser.  The current canvas spec only allows you to set colors as a
> string that goes through the CSS parser "rgb(1, 2, 3)", etc, or as a
> gradient.  The gradient color points are also CSS color strings, so
> creating gradients also requires going through the parser.

Oliver is well aware of this issue. He did some optimizations for  
parsing some color
types in <https://bugs.webkit.org/show_bug.cgi?id=3781>, but the  
"rbg()" and "rgba()"
notations still go through the CSS parser, which is slow.

> Does anyone have thoughts on allowing fillStyle / strokeStyle (and
> probably the gradient color points also) to take an array of RGB /
> RGBA?  This would allow for much more efficient color setup, and would
> be a very trivial change to the current DOM binding code.  I can
> submit a bug and patch to make the sfx / v8 DOM binding changes, but
> since it's something standardsy, I wanted to make sure to put it out
> there and solicit opinions.
>
> I think it's a pretty big weakness now that the only way you can set
> colors has to go through such a heavy parsing path.

It should be pretty easy to write a parser for rgb() and rgba()  
notations
which does not involve the flex-based CSS parser. I think we should
do that, and then see what performance issues remain.

I filed <https://bugs.webkit.org/show_bug.cgi?id=23110>

Simon



More information about the webkit-dev mailing list