Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak HTML parser yielding #9394

Conversation

pvollan
Copy link
Contributor

@pvollan pvollan commented Jan 31, 2023

6ce95a8

Tweak HTML parser yielding
https://bugs.webkit.org/show_bug.cgi?id=228780
rdar://81517847

Reviewed by Ryosuke Niwa.

Tweak html parser yielding to attempt to improve page load performance with respect to certain page load metrics.
This patch makes the parser yield if the page has not painted before and meaningful content has been loaded. So
far, this looks like a 1-2% improvement in page load times.

* Source/WebCore/html/parser/HTMLParserScheduler.cpp:
(WebCore::HTMLParserScheduler::shouldYieldBeforeExecutingScript):

Canonical link: https://commits.webkit.org/260011@main

2e8d963

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac   πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios   πŸ§ͺ mac-wk1   πŸ§ͺ api-gtk
βœ… πŸ›  tv   πŸ§ͺ mac-wk2
βœ… πŸ›  tv-sim   πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch-sim

@pvollan pvollan self-assigned this Jan 31, 2023
@pvollan pvollan added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Jan 31, 2023
@geoffreygaren
Copy link
Contributor

Seems like a neat idea to me; but I'd like to get Alan or Antti's opinion too.

@@ -120,6 +120,9 @@ bool HTMLParserScheduler::shouldYieldBeforeExecutingScript(const ScriptElement*
if (UNLIKELY(m_documentHasActiveParserYieldTokens))
return true;

if (document->view() && !document->view()->hasEverPainted() && document->isLayoutPending())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's funny there is a comment above saying:

If we've never painted before and a layout is pending, yield prior to running
scripts to give the page a chance to paint earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :) I should probably move that comment down to the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing!

Comment on lines 123 to 125
if (document->view() && !document->view()->hasEverPainted() && document->isLayoutPending())
return true;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also A/B test moving the "if (scriptElement)" block above this line. Forcing layout just because we parse an async or defer script tag seems wrong. Forcing layout before we execute a short inline script seems like an experimental question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, I will schedule that A/B test.

Thanks for reviewing!

@alanbaradlay
Copy link
Contributor

Does this "page load metrics" include time for first display (when we decide to show content to the user)? Curious if this has any impact on it (since now we may delay that pending layout potentially producing paints at a later time).

@alanbaradlay
Copy link
Contributor

(though also one could argue that processing more content first could lead to a non-empty layout sooner)

@pvollan
Copy link
Contributor Author

pvollan commented Jan 31, 2023

Does this "page load metrics" include time for first display (when we decide to show content to the user)? Curious if this has any impact on it (since now we may delay that pending layout potentially producing paints at a later time).

Yes, first meaningful paint is one of these page load metrics. So far, it looks like this change will improve this metric on some of the pages, but I am looking to run more tests.

Thanks for reviewing!

@pvollan pvollan force-pushed the eng/Tweak-HTML-parser-yielding branch from df59f34 to 2e8d963 Compare February 8, 2023 15:32
@pvollan pvollan added the merge-queue Applied to send a pull request to merge-queue label Feb 8, 2023
https://bugs.webkit.org/show_bug.cgi?id=228780
rdar://81517847

Reviewed by Ryosuke Niwa.

Tweak html parser yielding to attempt to improve page load performance with respect to certain page load metrics.
This patch makes the parser yield if the page has not painted before and meaningful content has been loaded. So
far, this looks like a 1-2% improvement in page load times.

* Source/WebCore/html/parser/HTMLParserScheduler.cpp:
(WebCore::HTMLParserScheduler::shouldYieldBeforeExecutingScript):

Canonical link: https://commits.webkit.org/260011@main
@webkit-commit-queue
Copy link
Collaborator

Committed 260011@main (6ce95a8): https://commits.webkit.org/260011@main

Reviewed commits have been landed. Closing PR #9394 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit 6ce95a8 into WebKit:main Feb 8, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Feb 8, 2023
@aj062
Copy link
Member

aj062 commented Feb 8, 2023

@pvollan This seems to have caused 60+ test failures on mac tester queues. EWS (unfinished) build on this PR also had failures, see https://ews-build.webkit.org/#/builders/73/builds/27722

Failures on post-commit bots: https://build.webkit.org/#/builders/48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
7 participants