GeezerVison is showing github.com — Remove scheduler sampling profiler shared array buffer (#20840) · react/react@8af27ae
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/SchedulerFeatureFlags.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 |
| 9 | 9 | export const enableSchedulerDebugging = false; | 10 | 10 | export const enableIsInputPending = false; | 11 | | -export const enableProfiling = false; | | 11 | +export const enableProfiling = __VARIANT__; | 12 | 12 |
| 13 | 13 | // TODO: enable to fix https://github.com/facebook/react/issues/20756. | 14 | 14 | export const enableSetImmediate = __VARIANT__; |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/SchedulerProfiling.js -56Lines changed: 0 additions & 56 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | import type {PriorityLevel} from './SchedulerPriorities'; | 11 | 11 | import {enableProfiling} from './SchedulerFeatureFlags'; | 12 | 12 |
| 13 | | -import {NoPriority} from './SchedulerPriorities'; | 14 | | - | 15 | 13 | let runIdCounter: number = 0; | 16 | 14 | let mainThreadIdCounter: number = 0; | 17 | 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 | | - | 52 | 16 | // Bytes per element is 4 | 53 | 17 | const INITIAL_EVENT_LOG_SIZE = 131072; | 54 | 18 | const MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes | @@ -116,8 +80,6 @@ export function markTaskStart( | 116 | 80 | ms: number, | 117 | 81 | ) { | 118 | 82 | if (enableProfiling) { | 119 | | - profilingState[QUEUE_SIZE]++; | 120 | | - | 121 | 83 | if (eventLog !== null) { | 122 | 84 | // performance.now returns a float, representing milliseconds. When the | 123 | 85 | // event is logged, it's coerced to an int. Convert to microseconds to | @@ -136,10 +98,6 @@ export function markTaskCompleted( | 136 | 98 | ms: number, | 137 | 99 | ) { | 138 | 100 | if (enableProfiling) { | 139 | | - profilingState[PRIORITY] = NoPriority; | 140 | | - profilingState[CURRENT_TASK_ID] = 0; | 141 | | - profilingState[QUEUE_SIZE]--; | 142 | | - | 143 | 101 | if (eventLog !== null) { | 144 | 102 | logEvent([TaskCompleteEvent, ms * 1000, task.id]); | 145 | 103 | } | @@ -155,8 +113,6 @@ export function markTaskCanceled( | 155 | 113 | ms: number, | 156 | 114 | ) { | 157 | 115 | if (enableProfiling) { | 158 | | - profilingState[QUEUE_SIZE]--; | 159 | | - | 160 | 116 | if (eventLog !== null) { | 161 | 117 | logEvent([TaskCancelEvent, ms * 1000, task.id]); | 162 | 118 | } | @@ -172,10 +128,6 @@ export function markTaskErrored( | 172 | 128 | ms: number, | 173 | 129 | ) { | 174 | 130 | if (enableProfiling) { | 175 | | - profilingState[PRIORITY] = NoPriority; | 176 | | - profilingState[CURRENT_TASK_ID] = 0; | 177 | | - profilingState[QUEUE_SIZE]--; | 178 | | - | 179 | 131 | if (eventLog !== null) { | 180 | 132 | logEvent([TaskErrorEvent, ms * 1000, task.id]); | 181 | 133 | } | @@ -193,10 +145,6 @@ export function markTaskRun( | 193 | 145 | if (enableProfiling) { | 194 | 146 | runIdCounter++; | 195 | 147 |
| 196 | | - profilingState[PRIORITY] = task.priorityLevel; | 197 | | - profilingState[CURRENT_TASK_ID] = task.id; | 198 | | - profilingState[CURRENT_RUN_ID] = runIdCounter; | 199 | | - | 200 | 148 | if (eventLog !== null) { | 201 | 149 | logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]); | 202 | 150 | } | @@ -205,10 +153,6 @@ export function markTaskRun( | 205 | 153 |
| 206 | 154 | export function markTaskYield(task: {id: number, ...}, ms: number) { | 207 | 155 | if (enableProfiling) { | 208 | | - profilingState[PRIORITY] = NoPriority; | 209 | | - profilingState[CURRENT_TASK_ID] = 0; | 210 | | - profilingState[CURRENT_RUN_ID] = 0; | 211 | | - | 212 | 156 | if (eventLog !== null) { | 213 | 157 | logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]); | 214 | 158 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/__tests__/SchedulerProfiling-test.js +14-64Lines changed: 14 additions & 64 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | 'use strict'; | 14 | 14 |
| 15 | 15 | let Scheduler; | 16 | | -let sharedProfilingArray; | 17 | 16 | // let runWithPriority; | 18 | 17 | let ImmediatePriority; | 19 | 18 | let UserBlockingPriority; | @@ -59,10 +58,6 @@ describe('Scheduler', () => { | 59 | 58 | jest.mock('scheduler', () => require('scheduler/unstable_mock')); | 60 | 59 | Scheduler = require('scheduler'); | 61 | 60 |
| 62 | | - sharedProfilingArray = new Int32Array( | 63 | | - Scheduler.unstable_Profiling.sharedProfilingBuffer, | 64 | | - ); | 65 | | - | 66 | 61 | // runWithPriority = Scheduler.unstable_runWithPriority; | 67 | 62 | ImmediatePriority = Scheduler.unstable_ImmediatePriority; | 68 | 63 | UserBlockingPriority = Scheduler.unstable_UserBlockingPriority; | @@ -76,20 +71,6 @@ describe('Scheduler', () => { | 76 | 71 | // shouldYield = Scheduler.unstable_shouldYield; | 77 | 72 | }); | 78 | 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 | | - | 93 | 74 | const TaskStartEvent = 1; | 94 | 75 | const TaskCompleteEvent = 2; | 95 | 76 | const TaskErrorEvent = 3; | @@ -272,23 +253,6 @@ describe('Scheduler', () => { | 272 | 253 | return '\n' + result; | 273 | 254 | } | 274 | 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 | | - | 292 | 256 | it('creates a basic flamegraph', () => { | 293 | 257 | Scheduler.unstable_Profiling.startLoggingProfilingEvents(); | 294 | 258 |
| @@ -297,35 +261,27 @@ describe('Scheduler', () => { | 297 | 261 | NormalPriority, | 298 | 262 | () => { | 299 | 263 | Scheduler.unstable_advanceTime(300); | 300 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 264 | + Scheduler.unstable_yieldValue('Yield 1'); | 301 | 265 | scheduleCallback( | 302 | 266 | UserBlockingPriority, | 303 | 267 | () => { | 304 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 268 | + Scheduler.unstable_yieldValue('Yield 2'); | 305 | 269 | Scheduler.unstable_advanceTime(300); | 306 | 270 | }, | 307 | 271 | {label: 'Bar'}, | 308 | 272 | ); | 309 | 273 | Scheduler.unstable_advanceTime(100); | 310 | | - Scheduler.unstable_yieldValue('Yield'); | | 274 | + Scheduler.unstable_yieldValue('Yield 3'); | 311 | 275 | return () => { | 312 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 276 | + Scheduler.unstable_yieldValue('Yield 4'); | 313 | 277 | Scheduler.unstable_advanceTime(300); | 314 | 278 | }; | 315 | 279 | }, | 316 | 280 | {label: 'Foo'}, | 317 | 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']); | 322 | 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']); | 329 | 285 |
| 330 | 286 | expect(stopProfilingAndPrintFlamegraph()).toEqual( | 331 | 287 | ` | @@ -340,19 +296,16 @@ Task 1 [Normal] │ ████████░░░░░░░ | 340 | 296 | Scheduler.unstable_Profiling.startLoggingProfilingEvents(); | 341 | 297 |
| 342 | 298 | const task = scheduleCallback(NormalPriority, () => { | 343 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 299 | + Scheduler.unstable_yieldValue('Yield 1'); | 344 | 300 | Scheduler.unstable_advanceTime(300); | 345 | | - Scheduler.unstable_yieldValue('Yield'); | | 301 | + Scheduler.unstable_yieldValue('Yield 2'); | 346 | 302 | return () => { | 347 | 303 | Scheduler.unstable_yieldValue('Continuation'); | 348 | 304 | Scheduler.unstable_advanceTime(200); | 349 | 305 | }; | 350 | 306 | }); | 351 | 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']); | 356 | 309 | Scheduler.unstable_advanceTime(100); | 357 | 310 |
| 358 | 311 | cancelCallback(task); | @@ -392,28 +345,25 @@ Task 1 [Normal] │██████🡐 errored | 392 | 345 | Scheduler.unstable_Profiling.startLoggingProfilingEvents(); | 393 | 346 |
| 394 | 347 | const task1 = scheduleCallback(NormalPriority, () => { | 395 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 348 | + Scheduler.unstable_yieldValue('Yield 1'); | 396 | 349 | Scheduler.unstable_advanceTime(300); | 397 | | - Scheduler.unstable_yieldValue('Yield'); | | 350 | + Scheduler.unstable_yieldValue('Yield 2'); | 398 | 351 | return () => { | 399 | 352 | Scheduler.unstable_yieldValue('Continuation'); | 400 | 353 | Scheduler.unstable_advanceTime(200); | 401 | 354 | }; | 402 | 355 | }); | 403 | 356 | const task2 = scheduleCallback(NormalPriority, () => { | 404 | | - Scheduler.unstable_yieldValue(getProfilingInfo()); | | 357 | + Scheduler.unstable_yieldValue('Yield 3'); | 405 | 358 | Scheduler.unstable_advanceTime(300); | 406 | | - Scheduler.unstable_yieldValue('Yield'); | | 359 | + Scheduler.unstable_yieldValue('Yield 4'); | 407 | 360 | return () => { | 408 | 361 | Scheduler.unstable_yieldValue('Continuation'); | 409 | 362 | Scheduler.unstable_advanceTime(200); | 410 | 363 | }; | 411 | 364 | }); | 412 | 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']); | 417 | 367 | Scheduler.unstable_advanceTime(100); | 418 | 368 |
| 419 | 369 | cancelCallback(task1); | |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/forks/SchedulerDOM.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,6 @@ import { | 25 | 25 | IdlePriority, | 26 | 26 | } from '../SchedulerPriorities'; | 27 | 27 | import { | 28 | | - sharedProfilingBuffer, | 29 | 28 | markTaskRun, | 30 | 29 | markTaskYield, | 31 | 30 | markTaskCompleted, | @@ -624,6 +623,5 @@ export const unstable_Profiling = enableProfiling | 624 | 623 | ? { | 625 | 624 | startLoggingProfilingEvents, | 626 | 625 | stopLoggingProfilingEvents, | 627 | | - sharedProfilingBuffer, | 628 | 626 | } | 629 | 627 | : null; |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/forks/SchedulerMock.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,7 +23,6 @@ import { | 23 | 23 | IdlePriority, | 24 | 24 | } from '../SchedulerPriorities'; | 25 | 25 | import { | 26 | | - sharedProfilingBuffer, | 27 | 26 | markTaskRun, | 28 | 27 | markTaskYield, | 29 | 28 | markTaskCompleted, | @@ -635,6 +634,5 @@ export const unstable_Profiling = enableProfiling | 635 | 634 | ? { | 636 | 635 | startLoggingProfilingEvents, | 637 | 636 | stopLoggingProfilingEvents, | 638 | | - sharedProfilingBuffer, | 639 | 637 | } | 640 | 638 | : null; |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/forks/SchedulerNoDOM.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,7 +23,6 @@ import { | 23 | 23 | IdlePriority, | 24 | 24 | } from '../SchedulerPriorities'; | 25 | 25 | import { | 26 | | - sharedProfilingBuffer, | 27 | 26 | markTaskRun, | 28 | 27 | markTaskYield, | 29 | 28 | markTaskCompleted, | @@ -470,6 +469,5 @@ export const unstable_Profiling = enableProfiling | 470 | 469 | ? { | 471 | 470 | startLoggingProfilingEvents, | 472 | 471 | stopLoggingProfilingEvents, | 473 | | - sharedProfilingBuffer, | 474 | 472 | } | 475 | 473 | : null; |
Collapse file Copy file name to clipboardExpand all lines: packages/scheduler/src/forks/SchedulerPostTaskOnly.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,6 @@ import { | 24 | 24 | IdlePriority, | 25 | 25 | } from '../SchedulerPriorities'; | 26 | 26 | import { | 27 | | - sharedProfilingBuffer, | 28 | 27 | markTaskRun, | 29 | 28 | markTaskYield, | 30 | 29 | markTaskCompleted, | @@ -595,6 +594,5 @@ export const unstable_Profiling = enableProfiling | 595 | 594 | ? { | 596 | 595 | startLoggingProfilingEvents, | 597 | 596 | stopLoggingProfilingEvents, | 598 | | - sharedProfilingBuffer, | 599 | 597 | } | 600 | 598 | : null; |
|