Remove scheduler sampling profiler shared array buffer (#20840)
No one has been using this data so there's no reason to collect it. Event log has been maintained and tests have been updated.
Brian Vaughn committed
Feb 18, 2021 at 11:21 UTC
8af27aeedbc6b00bc2ef49729fc84f116c70a27c
7 files changed
+15
-129
packages/scheduler/src/SchedulerFeatureFlags.js
+1
-1
@@ -8,7 +8,7 @@
8
9
export const enableSchedulerDebugging = false;
10
export const enableIsInputPending = false;
11
-export const enableProfiling = false;
11
+export const enableProfiling = __VARIANT__;
12
13
// TODO: enable to fix https://github.com/facebook/react/issues/20756.
14
export const enableSetImmediate = __VARIANT__;
packages/scheduler/src/SchedulerProfiling.js
-56
@@ -10,45 +10,9 @@
10
import type {PriorityLevel} from './SchedulerPriorities';
11
import {enableProfiling} from './SchedulerFeatureFlags';
12
13
-import {NoPriority} from './SchedulerPriorities';
14
-
13
let runIdCounter: number = 0;
14
let mainThreadIdCounter: number = 0;
15
18
-const isEnabledSharedArrayBuffer =
19
- // $FlowFixMe Flow doesn't know about SharedArrayBuffer
20
- typeof SharedArrayBuffer === 'function' &&
21
- // We only use SharedArrayBuffer when cross origin isolation is enabled.
22
- typeof window !== 'undefined' &&
23
- window.crossOriginIsolated === true;
24
-
25
-const profilingStateSize = 4;
26
-export const sharedProfilingBuffer = enableProfiling
27
- ? isEnabledSharedArrayBuffer
28
- ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
29
- : typeof ArrayBuffer === 'function'
30
- ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT)
31
- : null // Don't crash the init path on IE9
32
- : null;
33
-
34
-const profilingState =
35
- enableProfiling && sharedProfilingBuffer !== null
36
- ? new Int32Array(sharedProfilingBuffer)
37
- : []; // We can't read this but it helps save bytes for null checks
38
-
39
-const PRIORITY = 0;
40
-const CURRENT_TASK_ID = 1;
41
-const CURRENT_RUN_ID = 2;
42
-const QUEUE_SIZE = 3;
43
-
44
-if (enableProfiling) {
45
- profilingState[PRIORITY] = NoPriority;
46
- // This is maintained with a counter, because the size of the priority queue
47
- // array might include canceled tasks.
48
- profilingState[QUEUE_SIZE] = 0;
49
- profilingState[CURRENT_TASK_ID] = 0;
50
-}
51
-
16
// Bytes per element is 4
17
const INITIAL_EVENT_LOG_SIZE = 131072;
18
const MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes
@@ -116,8 +80,6 @@ export function markTaskStart(
80
ms: number,
81
) {
82
if (enableProfiling) {
119
- profilingState[QUEUE_SIZE]++;
120
-
83
if (eventLog !== null) {
84
// performance.now returns a float, representing milliseconds. When the
85
// event is logged, it's coerced to an int. Convert to microseconds to
@@ -136,10 +98,6 @@ export function markTaskCompleted(
98
ms: number,
99
) {
100
if (enableProfiling) {
139
- profilingState[PRIORITY] = NoPriority;
140
- profilingState[CURRENT_TASK_ID] = 0;
141
- profilingState[QUEUE_SIZE]--;
142
-
101
if (eventLog !== null) {
102
logEvent([TaskCompleteEvent, ms * 1000, task.id]);
103
}
@@ -155,8 +113,6 @@ export function markTaskCanceled(
113
ms: number,
114
) {
115
if (enableProfiling) {
158
- profilingState[QUEUE_SIZE]--;
159
-
116
if (eventLog !== null) {
117
logEvent([TaskCancelEvent, ms * 1000, task.id]);
118
}
@@ -172,10 +128,6 @@ export function markTaskErrored(
128
ms: number,
129
) {
130
if (enableProfiling) {
175
- profilingState[PRIORITY] = NoPriority;
176
- profilingState[CURRENT_TASK_ID] = 0;
177
- profilingState[QUEUE_SIZE]--;
178
-
131
if (eventLog !== null) {
132
logEvent([TaskErrorEvent, ms * 1000, task.id]);
133
}
@@ -193,10 +145,6 @@ export function markTaskRun(
145
if (enableProfiling) {
146
runIdCounter++;
147
196
- profilingState[PRIORITY] = task.priorityLevel;
197
- profilingState[CURRENT_TASK_ID] = task.id;
198
- profilingState[CURRENT_RUN_ID] = runIdCounter;
199
-
148
if (eventLog !== null) {
149
logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]);
150
}
@@ -205,10 +153,6 @@ export function markTaskRun(
153
154
export function markTaskYield(task: {id: number, ...}, ms: number) {
155
if (enableProfiling) {
208
- profilingState[PRIORITY] = NoPriority;
209
- profilingState[CURRENT_TASK_ID] = 0;
210
- profilingState[CURRENT_RUN_ID] = 0;
211
-
156
if (eventLog !== null) {
157
logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]);
158
}
packages/scheduler/src/__tests__/SchedulerProfiling-test.js
+14
-64
@@ -13,7 +13,6 @@
13
'use strict';
14
15
let Scheduler;
16
-let sharedProfilingArray;
16
// let runWithPriority;
17
let ImmediatePriority;
18
let UserBlockingPriority;
@@ -59,10 +58,6 @@ describe('Scheduler', () => {
58
jest.mock('scheduler', () => require('scheduler/unstable_mock'));
59
Scheduler = require('scheduler');
60
62
- sharedProfilingArray = new Int32Array(
63
- Scheduler.unstable_Profiling.sharedProfilingBuffer,
64
- );
65
-
61
// runWithPriority = Scheduler.unstable_runWithPriority;
62
ImmediatePriority = Scheduler.unstable_ImmediatePriority;
63
UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
@@ -76,20 +71,6 @@ describe('Scheduler', () => {
71
// shouldYield = Scheduler.unstable_shouldYield;
72
});
73
79
- const PRIORITY = 0;
80
- const CURRENT_TASK_ID = 1;
81
- const CURRENT_RUN_ID = 2;
82
- const QUEUE_SIZE = 3;
83
-
84
- afterEach(() => {
85
- if (sharedProfilingArray[QUEUE_SIZE] !== 0) {
86
- throw Error(
87
- 'Test exited, but the shared profiling buffer indicates that a task ' +
88
- 'is still running',
89
- );
90
- }
91
- });
92
-
74
const TaskStartEvent = 1;
75
const TaskCompleteEvent = 2;
76
const TaskErrorEvent = 3;
@@ -272,23 +253,6 @@ describe('Scheduler', () => {
253
return '\n' + result;
254
}
255
275
- function getProfilingInfo() {
276
- const queueSize = sharedProfilingArray[QUEUE_SIZE];
277
- if (queueSize === 0) {
278
- return 'Empty Queue';
279
- }
280
- const priorityLevel = sharedProfilingArray[PRIORITY];
281
- if (priorityLevel === 0) {
282
- return 'Suspended, Queue Size: ' + queueSize;
283
- }
284
- return (
285
- `Task: ${sharedProfilingArray[CURRENT_TASK_ID]}, ` +
286
- `Run: ${sharedProfilingArray[CURRENT_RUN_ID]}, ` +
287
- `Priority: ${priorityLevelToString(priorityLevel)}, ` +
288
- `Queue Size: ${sharedProfilingArray[QUEUE_SIZE]}`
289
- );
290
- }
291
-
256
it('creates a basic flamegraph', () => {
257
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
258
@@ -297,35 +261,27 @@ describe('Scheduler', () => {
261
NormalPriority,
262
() => {
263
Scheduler.unstable_advanceTime(300);
300
- Scheduler.unstable_yieldValue(getProfilingInfo());
264
+ Scheduler.unstable_yieldValue('Yield 1');
265
scheduleCallback(
266
UserBlockingPriority,
267
() => {
304
- Scheduler.unstable_yieldValue(getProfilingInfo());
268
+ Scheduler.unstable_yieldValue('Yield 2');
269
Scheduler.unstable_advanceTime(300);
270
},
271
{label: 'Bar'},
272
);
273
Scheduler.unstable_advanceTime(100);
310
- Scheduler.unstable_yieldValue('Yield');
274
+ Scheduler.unstable_yieldValue('Yield 3');
275
return () => {
312
- Scheduler.unstable_yieldValue(getProfilingInfo());
276
+ Scheduler.unstable_yieldValue('Yield 4');
277
Scheduler.unstable_advanceTime(300);
278
};
279
},
280
{label: 'Foo'},
281
);
318
- expect(Scheduler).toFlushAndYieldThrough([
319
- 'Task: 1, Run: 1, Priority: Normal, Queue Size: 1',
320
- 'Yield',
321
- ]);
282
+ expect(Scheduler).toFlushAndYieldThrough(['Yield 1', 'Yield 3']);
283
Scheduler.unstable_advanceTime(100);
323
- expect(Scheduler).toFlushAndYield([
324
- 'Task: 2, Run: 2, Priority: User-blocking, Queue Size: 2',
325
- 'Task: 1, Run: 3, Priority: Normal, Queue Size: 1',
326
- ]);
327
-
328
- expect(getProfilingInfo()).toEqual('Empty Queue');
284
+ expect(Scheduler).toFlushAndYield(['Yield 2', 'Yield 4']);
285
286
expect(stopProfilingAndPrintFlamegraph()).toEqual(
287
`
@@ -340,19 +296,16 @@ Task 1 [Normal] │ ████████░░░░░░░
296
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
297
298
const task = scheduleCallback(NormalPriority, () => {
343
- Scheduler.unstable_yieldValue(getProfilingInfo());
299
+ Scheduler.unstable_yieldValue('Yield 1');
300
Scheduler.unstable_advanceTime(300);
345
- Scheduler.unstable_yieldValue('Yield');
301
+ Scheduler.unstable_yieldValue('Yield 2');
302
return () => {
303
Scheduler.unstable_yieldValue('Continuation');
304
Scheduler.unstable_advanceTime(200);
305
};
306
});
307
352
- expect(Scheduler).toFlushAndYieldThrough([
353
- 'Task: 1, Run: 1, Priority: Normal, Queue Size: 1',
354
- 'Yield',
355
- ]);
308
+ expect(Scheduler).toFlushAndYieldThrough(['Yield 1', 'Yield 2']);
309
Scheduler.unstable_advanceTime(100);
310
311
cancelCallback(task);
@@ -392,28 +345,25 @@ Task 1 [Normal] │██████🡐 errored
345
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
346
347
const task1 = scheduleCallback(NormalPriority, () => {
395
- Scheduler.unstable_yieldValue(getProfilingInfo());
348
+ Scheduler.unstable_yieldValue('Yield 1');
349
Scheduler.unstable_advanceTime(300);
397
- Scheduler.unstable_yieldValue('Yield');
350
+ Scheduler.unstable_yieldValue('Yield 2');
351
return () => {
352
Scheduler.unstable_yieldValue('Continuation');
353
Scheduler.unstable_advanceTime(200);
354
};
355
});
356
const task2 = scheduleCallback(NormalPriority, () => {
404
- Scheduler.unstable_yieldValue(getProfilingInfo());
357
+ Scheduler.unstable_yieldValue('Yield 3');
358
Scheduler.unstable_advanceTime(300);
406
- Scheduler.unstable_yieldValue('Yield');
359
+ Scheduler.unstable_yieldValue('Yield 4');
360
return () => {
361
Scheduler.unstable_yieldValue('Continuation');
362
Scheduler.unstable_advanceTime(200);
363
};
364
});
365
413
- expect(Scheduler).toFlushAndYieldThrough([
414
- 'Task: 1, Run: 1, Priority: Normal, Queue Size: 2',
415
- 'Yield',
416
- ]);
366
+ expect(Scheduler).toFlushAndYieldThrough(['Yield 1', 'Yield 2']);
367
Scheduler.unstable_advanceTime(100);
368
369
cancelCallback(task1);
packages/scheduler/src/forks/SchedulerDOM.js
-2
@@ -25,7 +25,6 @@ import {
25
IdlePriority,
26
} from '../SchedulerPriorities';
27
import {
28
- sharedProfilingBuffer,
28
markTaskRun,
29
markTaskYield,
30
markTaskCompleted,
@@ -624,6 +623,5 @@ export const unstable_Profiling = enableProfiling
623
? {
624
startLoggingProfilingEvents,
625
stopLoggingProfilingEvents,
627
- sharedProfilingBuffer,
626
}
627
: null;
packages/scheduler/src/forks/SchedulerMock.js
-2
@@ -23,7 +23,6 @@ import {
23
IdlePriority,
24
} from '../SchedulerPriorities';
25
import {
26
- sharedProfilingBuffer,
26
markTaskRun,
27
markTaskYield,
28
markTaskCompleted,
@@ -635,6 +634,5 @@ export const unstable_Profiling = enableProfiling
634
? {
635
startLoggingProfilingEvents,
636
stopLoggingProfilingEvents,
638
- sharedProfilingBuffer,
637
}
638
: null;
packages/scheduler/src/forks/SchedulerNoDOM.js
-2
@@ -23,7 +23,6 @@ import {
23
IdlePriority,
24
} from '../SchedulerPriorities';
25
import {
26
- sharedProfilingBuffer,
26
markTaskRun,
27
markTaskYield,
28
markTaskCompleted,
@@ -470,6 +469,5 @@ export const unstable_Profiling = enableProfiling
469
? {
470
startLoggingProfilingEvents,
471
stopLoggingProfilingEvents,
473
- sharedProfilingBuffer,
472
}
473
: null;
packages/scheduler/src/forks/SchedulerPostTaskOnly.js
-2
@@ -24,7 +24,6 @@ import {
24
IdlePriority,
25
} from '../SchedulerPriorities';
26
import {
27
- sharedProfilingBuffer,
27
markTaskRun,
28
markTaskYield,
29
markTaskCompleted,
@@ -595,6 +594,5 @@ export const unstable_Profiling = enableProfiling
594
? {
595
startLoggingProfilingEvents,
596
stopLoggingProfilingEvents,
598
- sharedProfilingBuffer,
597
}
598
: null;