RESOLVED FIXED 89138
[cairo] improve putByteArray speed by avoiding max/min checks at Color construction.
https://bugs.webkit.org/show_bug.cgi?id=89138
Summary [cairo] improve putByteArray speed by avoiding max/min checks at Color constr...
arno.
Reported 2012-06-14 16:57:56 PDT
Hi, as explained in bug #89130, putByteArray constructs Color objects from unsigned char* elements. Color constructors takes integers arguments and checks they are between 0 and 255. As arguments are unsigned char*, we known for sure they're between 0 and 255, so we could probably try to skip this step.
Attachments
patch proposal (2.19 KB, patch)
2012-06-14 17:10 PDT, arno.
no flags
updated patch: unsigned char constructor for Color (2.58 KB, patch)
2012-06-19 12:03 PDT, arno.
no flags
patch v2.1: prevents build failure on mac (3.48 KB, patch)
2012-06-19 13:19 PDT, arno.
no flags
patch v2.2: using static_cast (3.49 KB, patch)
2012-06-19 15:59 PDT, arno.
no flags
patch v2.3: Color::createUnChecked function (4.42 KB, patch)
2012-06-20 14:35 PDT, arno.
no flags
arno.
Comment 1 2012-06-14 17:10:07 PDT
Created attachment 147682 [details] patch proposal
Martin Robinson
Comment 2 2012-06-18 14:28:35 PDT
Is it possible to simply have an unsigned char constructor for Color?
arno.
Comment 3 2012-06-19 12:03:02 PDT
Created attachment 148385 [details] updated patch: unsigned char constructor for Color
Martin Robinson
Comment 4 2012-06-19 12:26:58 PDT
Comment on attachment 148385 [details] updated patch: unsigned char constructor for Color View in context: https://bugs.webkit.org/attachment.cgi?id=148385&action=review > Source/WebCore/platform/graphics/Color.h:75 > +inline RGBA32 makeRGBUnsafe(int r, int g, int b) > +{ > + return 0xFF000000 | r << 16 | g << 8 | b; > +} > + > +inline RGBA32 makeRGBAUnsafe(int r, int g, int b, int a) > +{ > + return a << 24 | r << 16 | g << 8 | b; > +} > + Why not simply override these methods as well to take unsigneds?
Build Bot
Comment 5 2012-06-19 13:03:42 PDT
Comment on attachment 148385 [details] updated patch: unsigned char constructor for Color Attachment 148385 [details] did not pass mac-ews (mac): Output: http://queues.webkit.org/results/12992015
arno.
Comment 6 2012-06-19 13:19:07 PDT
Created attachment 148404 [details] patch v2.1: prevents build failure on mac
Igor Trindade Oliveira
Comment 7 2012-06-19 13:22:08 PDT
Comment on attachment 148404 [details] patch v2.1: prevents build failure on mac View in context: https://bugs.webkit.org/attachment.cgi?id=148404&action=review > Source/WebCore/platform/graphics/cg/ImageCG.cpp:131 > + m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], (int)pixel[3]); nit: normally we use c++ cast.
arno.
Comment 8 2012-06-19 15:59:09 PDT
Created attachment 148449 [details] patch v2.2: using static_cast
arno.
Comment 9 2012-06-19 17:34:47 PDT
(In reply to comment #4) > (From update of attachment 148385 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=148385&action=review > > > Source/WebCore/platform/graphics/Color.h:75 > > +inline RGBA32 makeRGBUnsafe(int r, int g, int b) > > +{ > > + return 0xFF000000 | r << 16 | g << 8 | b; > > +} > > + > > +inline RGBA32 makeRGBAUnsafe(int r, int g, int b, int a) > > +{ > > + return a << 24 | r << 16 | g << 8 | b; > > +} > > + > > Why not simply override these methods as well to take unsigneds? Because some parts of the code call makeRGB(float, ), and if we make makeRGB(unsigned char), those calls would become redundant. Also, maybe in some cases, it would be convenient to call makeRGBUnsafe with integers if we already known those integers are between 0 and 255 (I'm thinking for example at the colorFromPremultipliedARGB function)
arno.
Comment 10 2012-06-19 17:57:31 PDT
ccing adam barth as he's among one of the most few people to have review Color.h changes recently.
Adam Barth
Comment 11 2012-06-19 20:07:15 PDT
Is there a measurable performance gain from this change?
arno.
Comment 12 2012-06-20 11:15:03 PDT
(In reply to comment #11) > Is there a measurable performance gain from this change? http://renevier.net/misc/webkit_89138.html calls getImageData 100 times. Time it takes goes from 220ms to 165ms with GtkLauncher (185ms if function is not inlined)
Adam Barth
Comment 13 2012-06-20 12:58:24 PDT
This change seems valuable, but I'm slightly worried that it introduces a subtle overloading of the constructor. I wonder if it would make more sense to introduce a new static function for creating these objects so callers can be explicit about whether they want to unchecked version.
arno.
Comment 14 2012-06-20 14:35:55 PDT
Created attachment 148657 [details] patch v2.3: Color::createUnChecked function
Adam Barth
Comment 15 2012-06-20 17:59:08 PDT
Comment on attachment 148657 [details] patch v2.3: Color::createUnChecked function This looks much better. Thanks.
WebKit Review Bot
Comment 16 2012-06-20 23:09:04 PDT
Comment on attachment 148657 [details] patch v2.3: Color::createUnChecked function Clearing flags on attachment: 148657 Committed r120905: <http://trac.webkit.org/changeset/120905>
WebKit Review Bot
Comment 17 2012-06-20 23:09:09 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.