scheduler 0.16.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-info.json +5 -5
- package/cjs/scheduler-tracing.development.js +8 -88
- package/cjs/scheduler-tracing.production.min.js +2 -2
- package/cjs/scheduler-tracing.profiling.min.js +6 -5
- package/cjs/scheduler-unstable_mock.development.js +70 -80
- package/cjs/scheduler-unstable_mock.production.min.js +12 -12
- package/cjs/scheduler.development.js +106 -270
- package/cjs/scheduler.production.min.js +12 -13
- package/package.json +1 -1
- package/umd/scheduler-tracing.development.js +2 -2
- package/umd/scheduler-tracing.production.min.js +2 -2
- package/umd/scheduler-tracing.profiling.min.js +2 -2
- package/umd/scheduler-unstable_mock.development.js +671 -681
- package/umd/scheduler-unstable_mock.production.min.js +10 -10
- package/umd/scheduler.development.js +2 -2
- package/umd/scheduler.production.min.js +2 -2
- package/umd/scheduler.profiling.min.js +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v0.
|
|
1
|
+
/** @license React v0.19.0
|
|
2
2
|
* scheduler.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
@@ -15,29 +15,15 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
15
15
|
(function() {
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
19
|
-
|
|
20
18
|
var enableSchedulerDebugging = false;
|
|
21
|
-
var enableIsInputPending = false;
|
|
22
|
-
var enableMessageLoopImplementation = true;
|
|
23
19
|
var enableProfiling = true;
|
|
24
20
|
|
|
25
|
-
// works by scheduling a requestAnimationFrame, storing the time for the start
|
|
26
|
-
// of the frame, then scheduling a postMessage which gets scheduled after paint.
|
|
27
|
-
// Within the postMessage handler do as much work as possible until time + frame
|
|
28
|
-
// rate. By separating the idle call into a separate event tick we ensure that
|
|
29
|
-
// layout, paint and other browser work is counted against the available time.
|
|
30
|
-
// The frame rate is dynamically adjusted.
|
|
31
|
-
|
|
32
21
|
var requestHostCallback;
|
|
33
|
-
|
|
34
22
|
var requestHostTimeout;
|
|
35
23
|
var cancelHostTimeout;
|
|
36
24
|
var shouldYieldToHost;
|
|
37
25
|
var requestPaint;
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
|
|
41
27
|
if ( // If Scheduler runs in a non-DOM environment, it falls back to a naive
|
|
42
28
|
// implementation using setTimeout.
|
|
43
29
|
typeof window === 'undefined' || // Check if MessageChannel is supported, too.
|
|
@@ -98,17 +84,22 @@ typeof MessageChannel !== 'function') {
|
|
|
98
84
|
var _Date = window.Date;
|
|
99
85
|
var _setTimeout = window.setTimeout;
|
|
100
86
|
var _clearTimeout = window.clearTimeout;
|
|
101
|
-
var requestAnimationFrame = window.requestAnimationFrame;
|
|
102
|
-
var cancelAnimationFrame = window.cancelAnimationFrame;
|
|
103
87
|
|
|
104
88
|
if (typeof console !== 'undefined') {
|
|
105
|
-
// TODO:
|
|
89
|
+
// TODO: Scheduler no longer requires these methods to be polyfilled. But
|
|
90
|
+
// maybe we want to continue warning if they don't exist, to preserve the
|
|
91
|
+
// option to rely on it in the future?
|
|
92
|
+
var requestAnimationFrame = window.requestAnimationFrame;
|
|
93
|
+
var cancelAnimationFrame = window.cancelAnimationFrame; // TODO: Remove fb.me link
|
|
94
|
+
|
|
106
95
|
if (typeof requestAnimationFrame !== 'function') {
|
|
107
|
-
|
|
96
|
+
// Using console['error'] to evade Babel and ESLint
|
|
97
|
+
console['error']("This browser doesn't support requestAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
if (typeof cancelAnimationFrame !== 'function') {
|
|
111
|
-
|
|
101
|
+
// Using console['error'] to evade Babel and ESLint
|
|
102
|
+
console['error']("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
|
|
@@ -124,65 +115,21 @@ typeof MessageChannel !== 'function') {
|
|
|
124
115
|
};
|
|
125
116
|
}
|
|
126
117
|
|
|
127
|
-
var isRAFLoopRunning = false;
|
|
128
118
|
var isMessageLoopRunning = false;
|
|
129
119
|
var scheduledHostCallback = null;
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
// high frame rates > 120.
|
|
135
|
-
5 : // Use a heuristic to measure the frame rate and yield at the end of the
|
|
136
|
-
// frame. We start out assuming that we run at 30fps but then the
|
|
137
|
-
// heuristic tracking will adjust this value to a faster fps if we get
|
|
138
|
-
// more frequent animation frames.
|
|
139
|
-
33.33;
|
|
140
|
-
var prevRAFTime = -1;
|
|
141
|
-
var prevRAFInterval = -1;
|
|
142
|
-
var frameDeadline = 0;
|
|
143
|
-
var fpsLocked = false; // TODO: Make this configurable
|
|
144
|
-
// TODO: Adjust this based on priority?
|
|
145
|
-
|
|
146
|
-
var maxFrameLength = 300;
|
|
147
|
-
var needsPaint = false;
|
|
148
|
-
|
|
149
|
-
if (enableIsInputPending && navigator !== undefined && navigator.scheduling !== undefined && navigator.scheduling.isInputPending !== undefined) {
|
|
150
|
-
var scheduling = navigator.scheduling;
|
|
151
|
-
|
|
152
|
-
shouldYieldToHost = function () {
|
|
153
|
-
var currentTime = exports.unstable_now();
|
|
120
|
+
var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main
|
|
121
|
+
// thread, like user events. By default, it yields multiple times per frame.
|
|
122
|
+
// It does not attempt to align with frame boundaries, since most tasks don't
|
|
123
|
+
// need to be frame aligned; for those that do, use requestAnimationFrame.
|
|
154
124
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// the main thread, so the browser can perform high priority tasks. The
|
|
158
|
-
// main ones are painting and user input. If there's a pending paint or
|
|
159
|
-
// a pending input, then we should yield. But if there's neither, then
|
|
160
|
-
// we can yield less often while remaining responsive. We'll eventually
|
|
161
|
-
// yield regardless, since there could be a pending paint that wasn't
|
|
162
|
-
// accompanied by a call to `requestPaint`, or other main thread tasks
|
|
163
|
-
// like network events.
|
|
164
|
-
if (needsPaint || scheduling.isInputPending()) {
|
|
165
|
-
// There is either a pending paint or a pending input.
|
|
166
|
-
return true;
|
|
167
|
-
} // There's no pending input. Only yield if we've reached the max
|
|
168
|
-
// frame length.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return currentTime >= frameDeadline + maxFrameLength;
|
|
172
|
-
} else {
|
|
173
|
-
// There's still time left in the frame.
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
125
|
+
var yieldInterval = 5;
|
|
126
|
+
var deadline = 0; // TODO: Make this configurable
|
|
177
127
|
|
|
178
|
-
|
|
179
|
-
needsPaint = true;
|
|
180
|
-
};
|
|
181
|
-
} else {
|
|
128
|
+
{
|
|
182
129
|
// `isInputPending` is not available. Since we have no way of knowing if
|
|
183
130
|
// there's pending input, always yield at the end of the frame.
|
|
184
131
|
shouldYieldToHost = function () {
|
|
185
|
-
return exports.unstable_now() >=
|
|
132
|
+
return exports.unstable_now() >= deadline;
|
|
186
133
|
}; // Since we yield every frame regardless, `requestPaint` has no effect.
|
|
187
134
|
|
|
188
135
|
|
|
@@ -191,171 +138,60 @@ typeof MessageChannel !== 'function') {
|
|
|
191
138
|
|
|
192
139
|
exports.unstable_forceFrameRate = function (fps) {
|
|
193
140
|
if (fps < 0 || fps > 125) {
|
|
194
|
-
console
|
|
141
|
+
// Using console['error'] to evade Babel and ESLint
|
|
142
|
+
console['error']('forceFrameRate takes a positive int between 0 and 125, ' + 'forcing framerates higher than 125 fps is not unsupported');
|
|
195
143
|
return;
|
|
196
144
|
}
|
|
197
145
|
|
|
198
146
|
if (fps > 0) {
|
|
199
|
-
|
|
200
|
-
fpsLocked = true;
|
|
147
|
+
yieldInterval = Math.floor(1000 / fps);
|
|
201
148
|
} else {
|
|
202
149
|
// reset the framerate
|
|
203
|
-
|
|
204
|
-
fpsLocked = false;
|
|
150
|
+
yieldInterval = 5;
|
|
205
151
|
}
|
|
206
152
|
};
|
|
207
153
|
|
|
208
154
|
var performWorkUntilDeadline = function () {
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
// the message event.
|
|
214
|
-
|
|
215
|
-
frameDeadline = currentTime + frameLength;
|
|
216
|
-
var hasTimeRemaining = true;
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
var hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
|
|
220
|
-
|
|
221
|
-
if (!hasMoreWork) {
|
|
222
|
-
isMessageLoopRunning = false;
|
|
223
|
-
scheduledHostCallback = null;
|
|
224
|
-
} else {
|
|
225
|
-
// If there's more work, schedule the next message event at the end
|
|
226
|
-
// of the preceding one.
|
|
227
|
-
port.postMessage(null);
|
|
228
|
-
}
|
|
229
|
-
} catch (error) {
|
|
230
|
-
// If a scheduler task throws, exit the current browser task so the
|
|
231
|
-
// error can be observed.
|
|
232
|
-
port.postMessage(null);
|
|
233
|
-
throw error;
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
isMessageLoopRunning = false;
|
|
237
|
-
} // Yielding to the browser will give it a chance to paint, so we can
|
|
238
|
-
// reset this.
|
|
239
|
-
|
|
155
|
+
if (scheduledHostCallback !== null) {
|
|
156
|
+
var currentTime = exports.unstable_now(); // Yield after `yieldInterval` ms, regardless of where we are in the vsync
|
|
157
|
+
// cycle. This means there's always time remaining at the beginning of
|
|
158
|
+
// the message event.
|
|
240
159
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (scheduledHostCallback !== null) {
|
|
244
|
-
var _currentTime = exports.unstable_now();
|
|
245
|
-
|
|
246
|
-
var _hasTimeRemaining = frameDeadline - _currentTime > 0;
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
var _hasMoreWork = scheduledHostCallback(_hasTimeRemaining, _currentTime);
|
|
160
|
+
deadline = currentTime + yieldInterval;
|
|
161
|
+
var hasTimeRemaining = true;
|
|
250
162
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
163
|
+
try {
|
|
164
|
+
var hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
|
|
165
|
+
|
|
166
|
+
if (!hasMoreWork) {
|
|
167
|
+
isMessageLoopRunning = false;
|
|
168
|
+
scheduledHostCallback = null;
|
|
169
|
+
} else {
|
|
170
|
+
// If there's more work, schedule the next message event at the end
|
|
171
|
+
// of the preceding one.
|
|
258
172
|
port.postMessage(null);
|
|
259
|
-
throw error;
|
|
260
173
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
174
|
+
} catch (error) {
|
|
175
|
+
// If a scheduler task throws, exit the current browser task so the
|
|
176
|
+
// error can be observed.
|
|
177
|
+
port.postMessage(null);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
isMessageLoopRunning = false;
|
|
182
|
+
} // Yielding to the browser will give it a chance to paint, so we can
|
|
267
183
|
};
|
|
268
184
|
|
|
269
185
|
var channel = new MessageChannel();
|
|
270
186
|
var port = channel.port2;
|
|
271
187
|
channel.port1.onmessage = performWorkUntilDeadline;
|
|
272
188
|
|
|
273
|
-
var onAnimationFrame = function (rAFTime) {
|
|
274
|
-
if (scheduledHostCallback === null) {
|
|
275
|
-
// No scheduled work. Exit.
|
|
276
|
-
prevRAFTime = -1;
|
|
277
|
-
prevRAFInterval = -1;
|
|
278
|
-
isRAFLoopRunning = false;
|
|
279
|
-
return;
|
|
280
|
-
} // Eagerly schedule the next animation callback at the beginning of the
|
|
281
|
-
// frame. If the scheduler queue is not empty at the end of the frame, it
|
|
282
|
-
// will continue flushing inside that callback. If the queue *is* empty,
|
|
283
|
-
// then it will exit immediately. Posting the callback at the start of the
|
|
284
|
-
// frame ensures it's fired within the earliest possible frame. If we
|
|
285
|
-
// waited until the end of the frame to post the callback, we risk the
|
|
286
|
-
// browser skipping a frame and not firing the callback until the frame
|
|
287
|
-
// after that.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
isRAFLoopRunning = true;
|
|
291
|
-
requestAnimationFrame(function (nextRAFTime) {
|
|
292
|
-
_clearTimeout(rAFTimeoutID);
|
|
293
|
-
|
|
294
|
-
onAnimationFrame(nextRAFTime);
|
|
295
|
-
}); // requestAnimationFrame is throttled when the tab is backgrounded. We
|
|
296
|
-
// don't want to stop working entirely. So we'll fallback to a timeout loop.
|
|
297
|
-
// TODO: Need a better heuristic for backgrounded work.
|
|
298
|
-
|
|
299
|
-
var onTimeout = function () {
|
|
300
|
-
frameDeadline = exports.unstable_now() + frameLength / 2;
|
|
301
|
-
performWorkUntilDeadline();
|
|
302
|
-
rAFTimeoutID = _setTimeout(onTimeout, frameLength * 3);
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
rAFTimeoutID = _setTimeout(onTimeout, frameLength * 3);
|
|
306
|
-
|
|
307
|
-
if (prevRAFTime !== -1 && // Make sure this rAF time is different from the previous one. This check
|
|
308
|
-
// could fail if two rAFs fire in the same frame.
|
|
309
|
-
rAFTime - prevRAFTime > 0.1) {
|
|
310
|
-
var rAFInterval = rAFTime - prevRAFTime;
|
|
311
|
-
|
|
312
|
-
if (!fpsLocked && prevRAFInterval !== -1) {
|
|
313
|
-
// We've observed two consecutive frame intervals. We'll use this to
|
|
314
|
-
// dynamically adjust the frame rate.
|
|
315
|
-
//
|
|
316
|
-
// If one frame goes long, then the next one can be short to catch up.
|
|
317
|
-
// If two frames are short in a row, then that's an indication that we
|
|
318
|
-
// actually have a higher frame rate than what we're currently
|
|
319
|
-
// optimizing. For example, if we're running on 120hz display or 90hz VR
|
|
320
|
-
// display. Take the max of the two in case one of them was an anomaly
|
|
321
|
-
// due to missed frame deadlines.
|
|
322
|
-
if (rAFInterval < frameLength && prevRAFInterval < frameLength) {
|
|
323
|
-
frameLength = rAFInterval < prevRAFInterval ? prevRAFInterval : rAFInterval;
|
|
324
|
-
|
|
325
|
-
if (frameLength < 8.33) {
|
|
326
|
-
// Defensive coding. We don't support higher frame rates than 120hz.
|
|
327
|
-
// If the calculated frame length gets lower than 8, it is probably
|
|
328
|
-
// a bug.
|
|
329
|
-
frameLength = 8.33;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
prevRAFInterval = rAFInterval;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
prevRAFTime = rAFTime;
|
|
338
|
-
frameDeadline = rAFTime + frameLength; // We use the postMessage trick to defer idle work until after the repaint.
|
|
339
|
-
|
|
340
|
-
port.postMessage(null);
|
|
341
|
-
};
|
|
342
|
-
|
|
343
189
|
requestHostCallback = function (callback) {
|
|
344
190
|
scheduledHostCallback = callback;
|
|
345
191
|
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
port.postMessage(null);
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
if (!isRAFLoopRunning) {
|
|
353
|
-
// Start a rAF loop.
|
|
354
|
-
isRAFLoopRunning = true;
|
|
355
|
-
requestAnimationFrame(function (rAFTime) {
|
|
356
|
-
onAnimationFrame(rAFTime);
|
|
357
|
-
});
|
|
358
|
-
}
|
|
192
|
+
if (!isMessageLoopRunning) {
|
|
193
|
+
isMessageLoopRunning = true;
|
|
194
|
+
port.postMessage(null);
|
|
359
195
|
}
|
|
360
196
|
};
|
|
361
197
|
|
|
@@ -402,7 +238,7 @@ function siftUp(heap, node, i) {
|
|
|
402
238
|
var index = i;
|
|
403
239
|
|
|
404
240
|
while (true) {
|
|
405
|
-
var parentIndex =
|
|
241
|
+
var parentIndex = index - 1 >>> 1;
|
|
406
242
|
var parent = heap[parentIndex];
|
|
407
243
|
|
|
408
244
|
if (parent !== undefined && compare(parent, node) > 0) {
|
|
@@ -465,18 +301,18 @@ var IdlePriority = 5;
|
|
|
465
301
|
var runIdCounter = 0;
|
|
466
302
|
var mainThreadIdCounter = 0;
|
|
467
303
|
var profilingStateSize = 4;
|
|
468
|
-
var sharedProfilingBuffer =
|
|
304
|
+
var sharedProfilingBuffer = // $FlowFixMe Flow doesn't know about SharedArrayBuffer
|
|
469
305
|
typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer
|
|
470
306
|
typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9
|
|
471
|
-
|
|
472
|
-
var profilingState =
|
|
307
|
+
;
|
|
308
|
+
var profilingState = sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks
|
|
473
309
|
|
|
474
310
|
var PRIORITY = 0;
|
|
475
311
|
var CURRENT_TASK_ID = 1;
|
|
476
312
|
var CURRENT_RUN_ID = 2;
|
|
477
313
|
var QUEUE_SIZE = 3;
|
|
478
314
|
|
|
479
|
-
|
|
315
|
+
{
|
|
480
316
|
profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue
|
|
481
317
|
// array might include canceled tasks.
|
|
482
318
|
|
|
@@ -510,7 +346,8 @@ function logEvent(entries) {
|
|
|
510
346
|
eventLogSize *= 2;
|
|
511
347
|
|
|
512
348
|
if (eventLogSize > MAX_EVENT_LOG_SIZE) {
|
|
513
|
-
|
|
349
|
+
// Using console['error'] to evade Babel and ESLint
|
|
350
|
+
console['error']("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.');
|
|
514
351
|
stopLoggingProfilingEvents();
|
|
515
352
|
return;
|
|
516
353
|
}
|
|
@@ -539,82 +376,85 @@ function stopLoggingProfilingEvents() {
|
|
|
539
376
|
eventLogIndex = 0;
|
|
540
377
|
return buffer;
|
|
541
378
|
}
|
|
542
|
-
function markTaskStart(task,
|
|
543
|
-
|
|
379
|
+
function markTaskStart(task, ms) {
|
|
380
|
+
{
|
|
544
381
|
profilingState[QUEUE_SIZE]++;
|
|
545
382
|
|
|
546
383
|
if (eventLog !== null) {
|
|
547
|
-
|
|
384
|
+
// performance.now returns a float, representing milliseconds. When the
|
|
385
|
+
// event is logged, it's coerced to an int. Convert to microseconds to
|
|
386
|
+
// maintain extra degrees of precision.
|
|
387
|
+
logEvent([TaskStartEvent, ms * 1000, task.id, task.priorityLevel]);
|
|
548
388
|
}
|
|
549
389
|
}
|
|
550
390
|
}
|
|
551
|
-
function markTaskCompleted(task,
|
|
552
|
-
|
|
391
|
+
function markTaskCompleted(task, ms) {
|
|
392
|
+
{
|
|
553
393
|
profilingState[PRIORITY] = NoPriority;
|
|
554
394
|
profilingState[CURRENT_TASK_ID] = 0;
|
|
555
395
|
profilingState[QUEUE_SIZE]--;
|
|
556
396
|
|
|
557
397
|
if (eventLog !== null) {
|
|
558
|
-
logEvent([TaskCompleteEvent,
|
|
398
|
+
logEvent([TaskCompleteEvent, ms * 1000, task.id]);
|
|
559
399
|
}
|
|
560
400
|
}
|
|
561
401
|
}
|
|
562
|
-
function markTaskCanceled(task,
|
|
563
|
-
|
|
402
|
+
function markTaskCanceled(task, ms) {
|
|
403
|
+
{
|
|
564
404
|
profilingState[QUEUE_SIZE]--;
|
|
565
405
|
|
|
566
406
|
if (eventLog !== null) {
|
|
567
|
-
logEvent([TaskCancelEvent,
|
|
407
|
+
logEvent([TaskCancelEvent, ms * 1000, task.id]);
|
|
568
408
|
}
|
|
569
409
|
}
|
|
570
410
|
}
|
|
571
|
-
function markTaskErrored(task,
|
|
572
|
-
|
|
411
|
+
function markTaskErrored(task, ms) {
|
|
412
|
+
{
|
|
573
413
|
profilingState[PRIORITY] = NoPriority;
|
|
574
414
|
profilingState[CURRENT_TASK_ID] = 0;
|
|
575
415
|
profilingState[QUEUE_SIZE]--;
|
|
576
416
|
|
|
577
417
|
if (eventLog !== null) {
|
|
578
|
-
logEvent([TaskErrorEvent,
|
|
418
|
+
logEvent([TaskErrorEvent, ms * 1000, task.id]);
|
|
579
419
|
}
|
|
580
420
|
}
|
|
581
421
|
}
|
|
582
|
-
function markTaskRun(task,
|
|
583
|
-
|
|
422
|
+
function markTaskRun(task, ms) {
|
|
423
|
+
{
|
|
584
424
|
runIdCounter++;
|
|
585
425
|
profilingState[PRIORITY] = task.priorityLevel;
|
|
586
426
|
profilingState[CURRENT_TASK_ID] = task.id;
|
|
587
427
|
profilingState[CURRENT_RUN_ID] = runIdCounter;
|
|
588
428
|
|
|
589
429
|
if (eventLog !== null) {
|
|
590
|
-
logEvent([TaskRunEvent,
|
|
430
|
+
logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]);
|
|
591
431
|
}
|
|
592
432
|
}
|
|
593
433
|
}
|
|
594
|
-
function markTaskYield(task,
|
|
595
|
-
|
|
434
|
+
function markTaskYield(task, ms) {
|
|
435
|
+
{
|
|
596
436
|
profilingState[PRIORITY] = NoPriority;
|
|
597
437
|
profilingState[CURRENT_TASK_ID] = 0;
|
|
598
438
|
profilingState[CURRENT_RUN_ID] = 0;
|
|
599
439
|
|
|
600
440
|
if (eventLog !== null) {
|
|
601
|
-
logEvent([TaskYieldEvent,
|
|
441
|
+
logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]);
|
|
602
442
|
}
|
|
603
443
|
}
|
|
604
444
|
}
|
|
605
|
-
function markSchedulerSuspended(
|
|
606
|
-
|
|
445
|
+
function markSchedulerSuspended(ms) {
|
|
446
|
+
{
|
|
607
447
|
mainThreadIdCounter++;
|
|
608
448
|
|
|
609
449
|
if (eventLog !== null) {
|
|
610
|
-
logEvent([SchedulerSuspendEvent,
|
|
450
|
+
logEvent([SchedulerSuspendEvent, ms * 1000, mainThreadIdCounter]);
|
|
611
451
|
}
|
|
612
452
|
}
|
|
613
453
|
}
|
|
614
|
-
function markSchedulerUnsuspended(
|
|
615
|
-
|
|
454
|
+
function markSchedulerUnsuspended(ms) {
|
|
455
|
+
{
|
|
616
456
|
if (eventLog !== null) {
|
|
617
|
-
logEvent([SchedulerResumeEvent,
|
|
457
|
+
logEvent([SchedulerResumeEvent, ms * 1000, mainThreadIdCounter]);
|
|
618
458
|
}
|
|
619
459
|
}
|
|
620
460
|
}
|
|
@@ -637,8 +477,6 @@ var taskQueue = [];
|
|
|
637
477
|
var timerQueue = []; // Incrementing id counter. Used to maintain insertion order.
|
|
638
478
|
|
|
639
479
|
var taskIdCounter = 1; // Pausing the scheduler is useful for debugging.
|
|
640
|
-
|
|
641
|
-
var isSchedulerPaused = false;
|
|
642
480
|
var currentTask = null;
|
|
643
481
|
var currentPriorityLevel = NormalPriority; // This is set while performing work, to prevent re-entrancy.
|
|
644
482
|
|
|
@@ -660,7 +498,7 @@ function advanceTimers(currentTime) {
|
|
|
660
498
|
timer.sortIndex = timer.expirationTime;
|
|
661
499
|
push(taskQueue, timer);
|
|
662
500
|
|
|
663
|
-
|
|
501
|
+
{
|
|
664
502
|
markTaskStart(timer, currentTime);
|
|
665
503
|
timer.isQueued = true;
|
|
666
504
|
}
|
|
@@ -692,7 +530,7 @@ function handleTimeout(currentTime) {
|
|
|
692
530
|
}
|
|
693
531
|
|
|
694
532
|
function flushWork(hasTimeRemaining, initialTime) {
|
|
695
|
-
|
|
533
|
+
{
|
|
696
534
|
markSchedulerUnsuspended(initialTime);
|
|
697
535
|
} // We'll need a host callback the next time work is scheduled.
|
|
698
536
|
|
|
@@ -730,7 +568,7 @@ function flushWork(hasTimeRemaining, initialTime) {
|
|
|
730
568
|
currentPriorityLevel = previousPriorityLevel;
|
|
731
569
|
isPerformingWork = false;
|
|
732
570
|
|
|
733
|
-
|
|
571
|
+
{
|
|
734
572
|
var _currentTime = exports.unstable_now();
|
|
735
573
|
|
|
736
574
|
markSchedulerSuspended(_currentTime);
|
|
@@ -743,7 +581,7 @@ function workLoop(hasTimeRemaining, initialTime) {
|
|
|
743
581
|
advanceTimers(currentTime);
|
|
744
582
|
currentTask = peek(taskQueue);
|
|
745
583
|
|
|
746
|
-
while (currentTask !== null && !(enableSchedulerDebugging
|
|
584
|
+
while (currentTask !== null && !(enableSchedulerDebugging )) {
|
|
747
585
|
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
|
|
748
586
|
// This currentTask hasn't expired, and we've reached the deadline.
|
|
749
587
|
break;
|
|
@@ -763,7 +601,7 @@ function workLoop(hasTimeRemaining, initialTime) {
|
|
|
763
601
|
currentTask.callback = continuationCallback;
|
|
764
602
|
markTaskYield(currentTask, currentTime);
|
|
765
603
|
} else {
|
|
766
|
-
|
|
604
|
+
{
|
|
767
605
|
markTaskCompleted(currentTask, currentTime);
|
|
768
606
|
currentTask.isQueued = false;
|
|
769
607
|
}
|
|
@@ -910,7 +748,7 @@ function unstable_scheduleCallback(priorityLevel, callback, options) {
|
|
|
910
748
|
sortIndex: -1
|
|
911
749
|
};
|
|
912
750
|
|
|
913
|
-
|
|
751
|
+
{
|
|
914
752
|
newTask.isQueued = false;
|
|
915
753
|
}
|
|
916
754
|
|
|
@@ -935,7 +773,7 @@ function unstable_scheduleCallback(priorityLevel, callback, options) {
|
|
|
935
773
|
newTask.sortIndex = expirationTime;
|
|
936
774
|
push(taskQueue, newTask);
|
|
937
775
|
|
|
938
|
-
|
|
776
|
+
{
|
|
939
777
|
markTaskStart(newTask, currentTime);
|
|
940
778
|
newTask.isQueued = true;
|
|
941
779
|
} // Schedule a host callback, if needed. If we're already performing work,
|
|
@@ -952,11 +790,9 @@ function unstable_scheduleCallback(priorityLevel, callback, options) {
|
|
|
952
790
|
}
|
|
953
791
|
|
|
954
792
|
function unstable_pauseExecution() {
|
|
955
|
-
isSchedulerPaused = true;
|
|
956
793
|
}
|
|
957
794
|
|
|
958
795
|
function unstable_continueExecution() {
|
|
959
|
-
isSchedulerPaused = false;
|
|
960
796
|
|
|
961
797
|
if (!isHostCallbackScheduled && !isPerformingWork) {
|
|
962
798
|
isHostCallbackScheduled = true;
|
|
@@ -969,7 +805,7 @@ function unstable_getFirstCallbackNode() {
|
|
|
969
805
|
}
|
|
970
806
|
|
|
971
807
|
function unstable_cancelCallback(task) {
|
|
972
|
-
|
|
808
|
+
{
|
|
973
809
|
if (task.isQueued) {
|
|
974
810
|
var currentTime = exports.unstable_now();
|
|
975
811
|
markTaskCanceled(task, currentTime);
|
|
@@ -995,28 +831,28 @@ function unstable_shouldYield() {
|
|
|
995
831
|
}
|
|
996
832
|
|
|
997
833
|
var unstable_requestPaint = requestPaint;
|
|
998
|
-
var unstable_Profiling =
|
|
834
|
+
var unstable_Profiling = {
|
|
999
835
|
startLoggingProfilingEvents: startLoggingProfilingEvents,
|
|
1000
836
|
stopLoggingProfilingEvents: stopLoggingProfilingEvents,
|
|
1001
837
|
sharedProfilingBuffer: sharedProfilingBuffer
|
|
1002
|
-
}
|
|
838
|
+
} ;
|
|
1003
839
|
|
|
1004
|
-
exports.unstable_ImmediatePriority = ImmediatePriority;
|
|
1005
|
-
exports.unstable_UserBlockingPriority = UserBlockingPriority;
|
|
1006
|
-
exports.unstable_NormalPriority = NormalPriority;
|
|
1007
840
|
exports.unstable_IdlePriority = IdlePriority;
|
|
841
|
+
exports.unstable_ImmediatePriority = ImmediatePriority;
|
|
1008
842
|
exports.unstable_LowPriority = LowPriority;
|
|
1009
|
-
exports.
|
|
1010
|
-
exports.
|
|
1011
|
-
exports.
|
|
843
|
+
exports.unstable_NormalPriority = NormalPriority;
|
|
844
|
+
exports.unstable_Profiling = unstable_Profiling;
|
|
845
|
+
exports.unstable_UserBlockingPriority = UserBlockingPriority;
|
|
1012
846
|
exports.unstable_cancelCallback = unstable_cancelCallback;
|
|
1013
|
-
exports.unstable_wrapCallback = unstable_wrapCallback;
|
|
1014
|
-
exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;
|
|
1015
|
-
exports.unstable_shouldYield = unstable_shouldYield;
|
|
1016
|
-
exports.unstable_requestPaint = unstable_requestPaint;
|
|
1017
847
|
exports.unstable_continueExecution = unstable_continueExecution;
|
|
1018
|
-
exports.
|
|
848
|
+
exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;
|
|
1019
849
|
exports.unstable_getFirstCallbackNode = unstable_getFirstCallbackNode;
|
|
1020
|
-
exports.
|
|
850
|
+
exports.unstable_next = unstable_next;
|
|
851
|
+
exports.unstable_pauseExecution = unstable_pauseExecution;
|
|
852
|
+
exports.unstable_requestPaint = unstable_requestPaint;
|
|
853
|
+
exports.unstable_runWithPriority = unstable_runWithPriority;
|
|
854
|
+
exports.unstable_scheduleCallback = unstable_scheduleCallback;
|
|
855
|
+
exports.unstable_shouldYield = unstable_shouldYield;
|
|
856
|
+
exports.unstable_wrapCallback = unstable_wrapCallback;
|
|
1021
857
|
})();
|
|
1022
858
|
}
|