Bug 132793 - [WKWebView _updateScrollViewBackground] churns UI-and-CGColors while repainting
Summary: [WKWebView _updateScrollViewBackground] churns UI-and-CGColors while repainting
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
Keywords: InRadar
Depends on:
Reported: 2014-05-10 17:17 PDT by Tim Horton
Modified: 2014-05-11 10:53 PDT (History)
7 users (show)

See Also:

patch (2.73 KB, patch)
2014-05-10 20:20 PDT, Tim Horton
no flags Details | Formatted Diff | Diff
patch (3.90 KB, patch)
2014-05-10 20:54 PDT, Tim Horton
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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
Comment 2 Tim Horton 2014-05-10 20:20:35 PDT
Created attachment 231245 [details]
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]

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]
Comment 6 Tim Horton 2014-05-10 20:57:52 PDT
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.