Skip to content

Commit 12adaff

Browse files
Brian Vaughngaearon
Brian Vaughn
authored andcommitted
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.
1 parent b2bbee7 commit 12adaff

File tree

4 files changed

+15
-123
lines changed

4 files changed

+15
-123
lines changed

packages/scheduler/src/Scheduler.js

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
IdlePriority,
3333
} from './SchedulerPriorities';
3434
import {
35-
sharedProfilingBuffer,
3635
markTaskRun,
3736
markTaskYield,
3837
markTaskCompleted,
@@ -424,6 +423,5 @@ export const unstable_Profiling = enableProfiling
424423
? {
425424
startLoggingProfilingEvents,
426425
stopLoggingProfilingEvents,
427-
sharedProfilingBuffer,
428426
}
429427
: null;

packages/scheduler/src/SchedulerFeatureFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
export const enableSchedulerDebugging = false;
1010
export const enableIsInputPending = false;
11-
export const enableProfiling = false;
11+
export const enableProfiling = __VARIANT__;

packages/scheduler/src/SchedulerProfiling.js

-56
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,9 @@
1010
import type {PriorityLevel} from './SchedulerPriorities';
1111
import {enableProfiling} from './SchedulerFeatureFlags';
1212

13-
import {NoPriority} from './SchedulerPriorities';
14-
1513
let runIdCounter: number = 0;
1614
let mainThreadIdCounter: number = 0;
1715

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-
5216
// Bytes per element is 4
5317
const INITIAL_EVENT_LOG_SIZE = 131072;
5418
const MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes
@@ -116,8 +80,6 @@ export function markTaskStart(
11680
ms: number,
11781
) {
11882
if (enableProfiling) {
119-
profilingState[QUEUE_SIZE]++;
120-
12183
if (eventLog !== null) {
12284
// performance.now returns a float, representing milliseconds. When the
12385
// event is logged, it's coerced to an int. Convert to microseconds to
@@ -136,10 +98,6 @@ export function markTaskCompleted(
13698
ms: number,
13799
) {
138100
if (enableProfiling) {
139-
profilingState[PRIORITY] = NoPriority;
140-
profilingState[CURRENT_TASK_ID] = 0;
141-
profilingState[QUEUE_SIZE]--;
142-
143101
if (eventLog !== null) {
144102
logEvent([TaskCompleteEvent, ms * 1000, task.id]);
145103
}
@@ -155,8 +113,6 @@ export function markTaskCanceled(
155113
ms: number,
156114
) {
157115
if (enableProfiling) {
158-
profilingState[QUEUE_SIZE]--;
159-
160116
if (eventLog !== null) {
161117
logEvent([TaskCancelEvent, ms * 1000, task.id]);
162118
}
@@ -172,10 +128,6 @@ export function markTaskErrored(
172128
ms: number,
173129
) {
174130
if (enableProfiling) {
175-
profilingState[PRIORITY] = NoPriority;
176-
profilingState[CURRENT_TASK_ID] = 0;
177-
profilingState[QUEUE_SIZE]--;
178-
179131
if (eventLog !== null) {
180132
logEvent([TaskErrorEvent, ms * 1000, task.id]);
181133
}
@@ -193,10 +145,6 @@ export function markTaskRun(
193145
if (enableProfiling) {
194146
runIdCounter++;
195147

196-
profilingState[PRIORITY] = task.priorityLevel;
197-
profilingState[CURRENT_TASK_ID] = task.id;
198-
profilingState[CURRENT_RUN_ID] = runIdCounter;
199-
200148
if (eventLog !== null) {
201149
logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]);
202150
}
@@ -205,10 +153,6 @@ export function markTaskRun(
205153

206154
export function markTaskYield(task: {id: number, ...}, ms: number) {
207155
if (enableProfiling) {
208-
profilingState[PRIORITY] = NoPriority;
209-
profilingState[CURRENT_TASK_ID] = 0;
210-
profilingState[CURRENT_RUN_ID] = 0;
211-
212156
if (eventLog !== null) {
213157
logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]);
214158
}

packages/scheduler/src/__tests__/SchedulerProfiling-test.js

+14-64
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'use strict';
1414

1515
let Scheduler;
16-
let sharedProfilingArray;
1716
// let runWithPriority;
1817
let ImmediatePriority;
1918
let UserBlockingPriority;
@@ -59,10 +58,6 @@ describe('Scheduler', () => {
5958
jest.mock('scheduler', () => require('scheduler/unstable_mock'));
6059
Scheduler = require('scheduler');
6160

62-
sharedProfilingArray = new Int32Array(
63-
Scheduler.unstable_Profiling.sharedProfilingBuffer,
64-
);
65-
6661
// runWithPriority = Scheduler.unstable_runWithPriority;
6762
ImmediatePriority = Scheduler.unstable_ImmediatePriority;
6863
UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
@@ -76,20 +71,6 @@ describe('Scheduler', () => {
7671
// shouldYield = Scheduler.unstable_shouldYield;
7772
});
7873

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-
9374
const TaskStartEvent = 1;
9475
const TaskCompleteEvent = 2;
9576
const TaskErrorEvent = 3;
@@ -272,23 +253,6 @@ describe('Scheduler', () => {
272253
return '\n' + result;
273254
}
274255

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-
292256
it('creates a basic flamegraph', () => {
293257
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
294258

@@ -297,35 +261,27 @@ describe('Scheduler', () => {
297261
NormalPriority,
298262
() => {
299263
Scheduler.unstable_advanceTime(300);
300-
Scheduler.unstable_yieldValue(getProfilingInfo());
264+
Scheduler.unstable_yieldValue('Yield 1');
301265
scheduleCallback(
302266
UserBlockingPriority,
303267
() => {
304-
Scheduler.unstable_yieldValue(getProfilingInfo());
268+
Scheduler.unstable_yieldValue('Yield 2');
305269
Scheduler.unstable_advanceTime(300);
306270
},
307271
{label: 'Bar'},
308272
);
309273
Scheduler.unstable_advanceTime(100);
310-
Scheduler.unstable_yieldValue('Yield');
274+
Scheduler.unstable_yieldValue('Yield 3');
311275
return () => {
312-
Scheduler.unstable_yieldValue(getProfilingInfo());
276+
Scheduler.unstable_yieldValue('Yield 4');
313277
Scheduler.unstable_advanceTime(300);
314278
};
315279
},
316280
{label: 'Foo'},
317281
);
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']);
322283
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']);
329285

330286
expect(stopProfilingAndPrintFlamegraph()).toEqual(
331287
`
@@ -340,19 +296,16 @@ Task 1 [Normal] │ ████████░░░░░░░
340296
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
341297

342298
const task = scheduleCallback(NormalPriority, () => {
343-
Scheduler.unstable_yieldValue(getProfilingInfo());
299+
Scheduler.unstable_yieldValue('Yield 1');
344300
Scheduler.unstable_advanceTime(300);
345-
Scheduler.unstable_yieldValue('Yield');
301+
Scheduler.unstable_yieldValue('Yield 2');
346302
return () => {
347303
Scheduler.unstable_yieldValue('Continuation');
348304
Scheduler.unstable_advanceTime(200);
349305
};
350306
});
351307

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']);
356309
Scheduler.unstable_advanceTime(100);
357310

358311
cancelCallback(task);
@@ -392,28 +345,25 @@ Task 1 [Normal] │██████🡐 errored
392345
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
393346

394347
const task1 = scheduleCallback(NormalPriority, () => {
395-
Scheduler.unstable_yieldValue(getProfilingInfo());
348+
Scheduler.unstable_yieldValue('Yield 1');
396349
Scheduler.unstable_advanceTime(300);
397-
Scheduler.unstable_yieldValue('Yield');
350+
Scheduler.unstable_yieldValue('Yield 2');
398351
return () => {
399352
Scheduler.unstable_yieldValue('Continuation');
400353
Scheduler.unstable_advanceTime(200);
401354
};
402355
});
403356
const task2 = scheduleCallback(NormalPriority, () => {
404-
Scheduler.unstable_yieldValue(getProfilingInfo());
357+
Scheduler.unstable_yieldValue('Yield 3');
405358
Scheduler.unstable_advanceTime(300);
406-
Scheduler.unstable_yieldValue('Yield');
359+
Scheduler.unstable_yieldValue('Yield 4');
407360
return () => {
408361
Scheduler.unstable_yieldValue('Continuation');
409362
Scheduler.unstable_advanceTime(200);
410363
};
411364
});
412365

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']);
417367
Scheduler.unstable_advanceTime(100);
418368

419369
cancelCallback(task1);

0 commit comments

Comments
 (0)