Bug 142015

Summary: [WK2] REGRESSION(r180465): WebKit::WebPage::editorState() triggers a layout
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: WebKit2Assignee: Enrica Casucci <enrica>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, cdumez, commit-queue, enrica, kling, rniwa, sam, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 127832, 141777    
Attachments:
Description Flags
WIP Patch
buildbot: commit-queue-
Archive of layout-test-results from ews105 for mac-mavericks-wk2
none
WIP Patch
none
WIP Patch
buildbot: commit-queue-
Archive of layout-test-results from ews104 for mac-mavericks-wk2
none
WIP Patch
buildbot: commit-queue-
Archive of layout-test-results from ews106 for mac-mavericks-wk2
none
Patch3 ap: review+

Description Ryosuke Niwa 2015-02-25 03:10:07 PST
After http://trac.webkit.org/changeset/180465/, we syncrhnously trigger layout upon every selection change.
Comment 1 Radar WebKit Bug Importer 2015-02-25 03:11:34 PST
<rdar://problem/19951047>
Comment 2 Sam Weinig 2015-02-25 08:32:28 PST
From the patch (and I might be reading it wrong), it looks like we had this behavior already on iOS, so it is regression only on Mac. Is that correct?
Comment 3 Ryosuke Niwa 2015-02-25 10:00:42 PST
(In reply to comment #2)
> From the patch (and I might be reading it wrong), it looks like we had this
> behavior already on iOS, so it is regression only on Mac. Is that correct?

Yes but that code was added in http://trac.webkit.org/changeset/171015 so this could still be a regression since our last release...
Comment 4 Enrica Casucci 2015-02-25 10:13:09 PST
(In reply to comment #3)
> (In reply to comment #2)
> > From the patch (and I might be reading it wrong), it looks like we had this
> > behavior already on iOS, so it is regression only on Mac. Is that correct?
> 
> Yes but that code was added in http://trac.webkit.org/changeset/171015 so
> this could still be a regression since our last release...

How can we return this type of information without layout?
Comment 5 Sam Weinig 2015-02-25 10:17:15 PST
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > From the patch (and I might be reading it wrong), it looks like we had this
> > > behavior already on iOS, so it is regression only on Mac. Is that correct?
> > 
> > Yes but that code was added in http://trac.webkit.org/changeset/171015 so
> > this could still be a regression since our last release...
> 
> How can we return this type of information without layout?

I am not sure that is necessarily the right question. We might want to look at this a bit more removed, and consider if we really need to grab this information everytime the selection changes, or whether we can wait until the next style recalc/layout happens to tell the UIProcess that the editor state has changed.
Comment 6 Ryosuke Niwa 2015-02-25 10:20:49 PST
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > From the patch (and I might be reading it wrong), it looks like we had this
> > > behavior already on iOS, so it is regression only on Mac. Is that correct?
> > 
> > Yes but that code was added in http://trac.webkit.org/changeset/171015 so
> > this could still be a regression since our last release...
> 
> How can we return this type of information without layout?

I don't think we can.  I think we should instead delay when the font information is fetched. Right now, we seem to be updating it each time selection changes within a single task (e.g. when JS modifies it multiple times) but we shouldn't have to do that because font panel, keyboard, etc... won't be interacting with users faster than 60fps.
Comment 7 Chris Dumez 2015-02-25 14:53:09 PST
Created attachment 247349 [details]
WIP Patch
Comment 8 Build Bot 2015-02-25 15:13:37 PST
Comment on attachment 247349 [details]
WIP Patch

Attachment 247349 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5953856059998208

New failing tests:
platform/mac/editing/input/selection-change-closes-typing-2.html
platform/mac/editing/input/selection-change-closes-typing.html
editing/secure-input/password-input-focusing.html
Comment 9 Build Bot 2015-02-25 15:13:40 PST
Created attachment 247351 [details]
Archive of layout-test-results from ews105 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 10 Chris Dumez 2015-02-25 15:35:28 PST
I see a 31% progression on Speedometer locally with my WIP patch.
Comment 11 Chris Dumez 2015-02-25 15:42:48 PST
Created attachment 247353 [details]
WIP Patch
Comment 12 Chris Dumez 2015-02-25 15:57:25 PST
Created attachment 247357 [details]
WIP Patch
Comment 13 Build Bot 2015-02-25 16:30:53 PST
Comment on attachment 247357 [details]
WIP Patch

Attachment 247357 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5103672115593216

New failing tests:
editing/secure-input/password-input-focusing.html
Comment 14 Build Bot 2015-02-25 16:30:58 PST
Created attachment 247362 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 15 Chris Dumez 2015-02-25 16:53:49 PST
Created attachment 247366 [details]
WIP Patch
Comment 16 Build Bot 2015-02-25 17:49:44 PST
Comment on attachment 247366 [details]
WIP Patch

Attachment 247366 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6710393611223040

New failing tests:
platform/mac/editing/input/selection-change-closes-typing-2.html
platform/mac/editing/input/selection-change-closes-typing.html
editing/secure-input/password-input-focusing.html
Comment 17 Build Bot 2015-02-25 17:49:47 PST
Created attachment 247375 [details]
Archive of layout-test-results from ews106 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 18 Enrica Casucci 2015-02-26 17:05:59 PST
Created attachment 247469 [details]
Patch3
Comment 19 WebKit Commit Bot 2015-02-26 17:07:50 PST
Attachment 247469 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm:333:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/UIProcess/WebPageProxy.h:543:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/UIProcess/API/mac/WKView.mm:2522:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/API/mac/WKView.mm:2523:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebKit2/UIProcess/API/mac/WKView.mm:2524:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 5 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 20 Chris Dumez 2015-02-26 17:13:45 PST
Comment on attachment 247469 [details]
Patch3

Looks good and I have confirmed that it fixes the perf regression locally. I'll let a WK2 Owner review this though.
Comment 21 Alexey Proskuryakov 2015-02-27 10:28:07 PST
Comment on attachment 247469 [details]
Patch3

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

> Source/WebKit2/UIProcess/API/mac/WKView.mm:748
> +        _data->_page->fontAtSelection([self](const String& fontName, double fontSize, bool selectionHasMultipleFonts, CallbackBase::Error error) {

Do we actually need to capture self here?

> Source/WebKit2/UIProcess/API/mac/WKView.mm:750
> +            NSFont *font = [NSFont fontWithName:fontName size:fontSize];
> +            [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:selectionHasMultipleFonts];

Should we bail out if there was no font found (e.g. an SVG font or another loadable font is in use)?
Comment 22 Enrica Casucci 2015-02-27 10:48:21 PST
(In reply to comment #21)
> Comment on attachment 247469 [details]
> Patch3
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=247469&action=review
> 
> > Source/WebKit2/UIProcess/API/mac/WKView.mm:748
> > +        _data->_page->fontAtSelection([self](const String& fontName, double fontSize, bool selectionHasMultipleFonts, CallbackBase::Error error) {
> 
> Do we actually need to capture self here?
No, I'll remove it.
> 
> > Source/WebKit2/UIProcess/API/mac/WKView.mm:750
> > +            NSFont *font = [NSFont fontWithName:fontName size:fontSize];
> > +            [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:selectionHasMultipleFonts];
> 
> Should we bail out if there was no font found (e.g. an SVG font or another
> loadable font is in use)?
Yes, there is no point in calling the font manager.
thanks for the review.
Comment 23 Enrica Casucci 2015-02-27 10:51:01 PST
Committed revision 180768.