Title: [274673] trunk/Source/WebCore
Revision
274673
Author
[email protected]
Date
2021-03-18 14:19:16 -0700 (Thu, 18 Mar 2021)

Log Message

Switch out of scheduled resource load mode only after async scripts have run
https://bugs.webkit.org/show_bug.cgi?id=223464

Reviewed by Geoffrey Garen.

Async scripts may generate more resource loads that benefit from scheduling.

* page/Page.cpp:
(WebCore::Page::prioritizeVisibleResources):

Also factor the mode transition into a lambda.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274672 => 274673)


--- trunk/Source/WebCore/ChangeLog	2021-03-18 20:58:23 UTC (rev 274672)
+++ trunk/Source/WebCore/ChangeLog	2021-03-18 21:19:16 UTC (rev 274673)
@@ -1,3 +1,17 @@
+2021-03-18  Antti Koivisto  <[email protected]>
+
+        Switch out of scheduled resource load mode only after async scripts have run
+        https://bugs.webkit.org/show_bug.cgi?id=223464
+
+        Reviewed by Geoffrey Garen.
+
+        Async scripts may generate more resource loads that benefit from scheduling.
+
+        * page/Page.cpp:
+        (WebCore::Page::prioritizeVisibleResources):
+        
+        Also factor the mode transition into a lambda.
+        
 2021-03-18  Chris Dumez  <[email protected]>
 
         Avoid heap allocation under BaseAudioContext::sourceNodeDidFinishPlayback()

Modified: trunk/Source/WebCore/page/Page.cpp (274672 => 274673)


--- trunk/Source/WebCore/page/Page.cpp	2021-03-18 20:58:23 UTC (rev 274672)
+++ trunk/Source/WebCore/page/Page.cpp	2021-03-18 21:19:16 UTC (rev 274673)
@@ -116,6 +116,7 @@
 #include "SVGImage.h"
 #include "ScriptController.h"
 #include "ScriptDisallowedScope.h"
+#include "ScriptRunner.h"
 #include "ScriptedAnimationController.h"
 #include "ScrollLatchingController.h"
 #include "ScrollingCoordinator.h"
@@ -1717,14 +1718,28 @@
     forEachDocument([&] (Document& document) {
         toPrioritize.appendVector(document.cachedResourceLoader().visibleResourcesToPrioritize());
     });
+    
+    auto computeSchedulingMode = [&] {
+        auto& document = *mainFrame().document();
+        // Parsing generates resource loads.
+        if (document.parsing())
+            return LoadSchedulingMode::Prioritized;
+        
+        // Async script execution may generate more resource loads that benefit from prioritization.
+        if (document.scriptRunner().hasPendingScripts())
+            return LoadSchedulingMode::Prioritized;
+        
+        // We still haven't finished loading the visible resources.
+        if (!toPrioritize.isEmpty())
+            return LoadSchedulingMode::Prioritized;
+        
+        return LoadSchedulingMode::Direct;
+    };
+    
+    setLoadSchedulingMode(computeSchedulingMode());
 
-    if (toPrioritize.isEmpty()) {
-        if (!mainFrame().document()->parsing()) {
-            // All visible resources have been loaded and we are done with parsing. Stop scheduling.
-            setLoadSchedulingMode(LoadSchedulingMode::Direct);
-        }
+    if (toPrioritize.isEmpty())
         return;
-    }
 
     auto resourceLoaders = toPrioritize.map([](auto* resource) {
         return resource->loader();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to