Add test of scheduler overhead (#16260)
Sebastian Markbåge committed
Aug 1, 2019 at 17:13 UTC
95674af2ef3c3028d903272f606295209fbb6b65
1 file changed
+91
-2
fixtures/scheduler/index.html
+91
-2
@@ -119,9 +119,37 @@
119
<div id="test-9"></div>
120
</div>
121
</li>
122
+ <li>
123
+ <p>Runs scheduled JS work for 99% of the frame time when nothing else is using the thread.</p>
124
+ <p><b>NOTE:</b> Try this test both when nothing else is running and when something is using the compositor thread in another visible tab with video or <a href="https://www.shadertoy.com/view/MtffDX">WebGL content</a> (Shift+Click).</p>
125
+ <button onClick="runTestTen()">Run Test 10</button>
126
+ <div><b>Expected:</b></div>
127
+ <div id="test-10-expected">
128
+ </div>
129
+ <div> -------------------------------------------------</div>
130
+ <div> If you see the same above and below it's correct.
131
+ <div> -------------------------------------------------</div>
132
+ <div><b>Actual:</b></div>
133
+ <div id="test-10"></div>
134
+ </div>
135
+ </li>
136
+ <li>
137
+ <p>Runs scheduled JS work more than 95% of the frame time when inserting DOM nodes.</p>
138
+ <p><b>NOTE:</b> Try this test both when nothing else is running and when something is using the compositor thread in another visible tab with video or <a href="https://www.shadertoy.com/view/MtffDX">WebGL content</a> (Shift+Click).</p>
139
+ <button onClick="runTestEleven()">Run Test 11</button>
140
+ <div><b>Expected:</b></div>
141
+ <div id="test-11-expected">
142
+ </div>
143
+ <div> -------------------------------------------------</div>
144
+ <div> If you see the same above and below it's correct.
145
+ <div> -------------------------------------------------</div>
146
+ <div><b>Actual:</b></div>
147
+ <div id="test-11"></div>
148
+ </div>
149
+ </li>
150
</ol>
123
- <script src="../../build/node_modules/react/umd/react.development.js"></script>
124
- <script src="../../build/node_modules/scheduler/umd/scheduler.development.js"></script>
151
+ <script src="../../build/node_modules/react/umd/react.production.min.js"></script>
152
+ <script src="../../build/node_modules/scheduler/umd/scheduler.production.min.js"></script>
153
<script src="https://unpkg.com/babel-standalone@6/babel.js"></script>
154
<script type="text/babel">
155
const {
@@ -267,6 +295,16 @@ const expectedResults = [
295
'Using new frame time!',
296
'Finished!',
297
],
298
+ // test 10
299
+ [
300
+ 'Running work for 10 seconds...',
301
+ 'Ran scheduled work for >99% of the time.',
302
+ ],
303
+ // test 11
304
+ [
305
+ 'Running work for 10 seconds...',
306
+ 'Ran scheduled work for >95% of the time.',
307
+ ],
308
];
309
function runTestOne() {
310
// Test 1
@@ -637,6 +675,57 @@ function runTestNine() {
675
});
676
}
677
678
+function runTestTen() {
679
+ clearTestResult(10);
680
+ updateTestResult(10, `Running work for 10 seconds...`);
681
+ var testStartTime = now();
682
+ var accumulatedWork = 0
683
+ function loop() {
684
+ var startTime = now();
685
+ while (!shouldYield()) {}
686
+ var endTime = now();
687
+ accumulatedWork += endTime - startTime;
688
+ var runTime = endTime - testStartTime;
689
+ if (runTime > 10000) {
690
+ updateTestResult(10, `Ran scheduled work for ${(100 * accumulatedWork / runTime).toFixed(2)}% of the time.`);
691
+ displayTestResult(10);
692
+ return;
693
+ }
694
+ scheduleCallback(NormalPriority, loop);
695
+ }
696
+ scheduleCallback(NormalPriority, loop);
697
+}
698
+
699
+function runTestEleven() {
700
+ clearTestResult(11);
701
+ updateTestResult(11, `Running work for 10 seconds...`);
702
+ var testStartTime = now();
703
+ var lastInsertion = 0;
704
+ var accumulatedWork = 0
705
+ function loop() {
706
+ var startTime = now();
707
+ var timeSinceLastDOMInteraction = startTime - lastInsertion;
708
+ if (timeSinceLastDOMInteraction > 15) {
709
+ lastInsertion = startTime;
710
+ var node = document.createElement('div');
711
+ node.textContent = startTime;
712
+ document.body.appendChild(node);
713
+ document.body.clientHeight; // force layout
714
+ }
715
+ while (!shouldYield()) {}
716
+ var endTime = now();
717
+ accumulatedWork += endTime - startTime;
718
+ var runTime = endTime - testStartTime;
719
+ if (runTime > 10000) {
720
+ updateTestResult(11, `Ran scheduled work for ${(100 * accumulatedWork / runTime).toFixed(2)}% of the time.`);
721
+ displayTestResult(11);
722
+ return;
723
+ }
724
+ scheduleCallback(NormalPriority, loop);
725
+ }
726
+ scheduleCallback(NormalPriority, loop);
727
+}
728
+
729
</script type="text/babel">
730
</body>
731
</html>