Bug 132793

Summary: [WKWebView _updateScrollViewBackground] churns UI-and-CGColors while repainting
Product: WebKit Reporter: Tim Horton <thorton>
Component: WebKit2Assignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, bdakin, commit-queue, darin, sam, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch
none
patch mitz: review+

Description Tim Horton 2014-05-10 17:17:07 PDT
Every layer tree commit, we churn various different color objects in _updateScrollViewBackground. There's no reason for this, and it's a complete waste of ~2.5% of the UI process time while repainting quickly.
Comment 1 Radar WebKit Bug Importer 2014-05-10 17:17:31 PDT
<rdar://problem/16877870>
Comment 2 Tim Horton 2014-05-10 20:20:35 PDT
Created attachment 231245 [details]
patch
Comment 3 WebKit Commit Bot 2014-05-10 20:22:21 PDT
Attachment 231245 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:455:  The parameter name "_currentScrollViewBackgroundColor" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 mitz 2014-05-10 20:48:31 PDT
Comment on attachment 231245 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=231245&action=review

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:129
> +    WebCore::Color _currentScrollViewBackgroundColor;

What does the word “current” add here?

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:452
> +        color = WebCore::Color(color.red(), color.green(), color.blue(), opacity * 255);

opacity * 255 is not rounding correctly. If you use colorWithOverrideAlpha() from Color.h you’ll get the correct rounding behavior. Something like:
    color.setRGB(colorWithOverrideAlpha(color.rgb(), opacity);

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:455
> +    if (_currentScrollViewBackgroundColor.isValid() && _currentScrollViewBackgroundColor == color)

Color’s operator== compares validity, so I don’t understand what the isValid() check here is doing.
Comment 5 Tim Horton 2014-05-10 20:54:32 PDT
Created attachment 231247 [details]
patch
Comment 6 Tim Horton 2014-05-10 20:57:52 PDT
http://trac.webkit.org/changeset/168594
Comment 7 Darin Adler 2014-05-11 10:40:06 PDT
Should we add a UIColor cache too, not just a CGColor cache?
Comment 8 Tim Horton 2014-05-11 10:53:20 PDT
(In reply to comment #7)
> Should we add a UIColor cache too, not just a CGColor cache?

Maybe! Though, with this resolved, I don't see UIColor creation being slow anywhere in traces.