Skip to content

Commit 4129ea8

Browse files
authored
set priority on TaskController instead of on postTask/yield (#27295)
## Summary passing both a signal and a priority to `postTask`/`yield` in chrome causes memory to spike and potentially causes OOMs. a fix for this has landed in chrome 118, but we can avoid the issue in earlier versions by setting priority on just the TaskController instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1469367 ## How did you test this change? ``` yarn test SchedulerPostTask ```
1 parent 2f36872 commit 4129ea8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ describe('SchedulerPostTask', () => {
8383
const scheduler = {};
8484
global.scheduler = scheduler;
8585

86-
scheduler.postTask = function (callback, {priority, signal}) {
86+
scheduler.postTask = function (callback, {signal}) {
87+
const {priority} = signal;
8788
const id = idCounter++;
8889
log(
8990
`Post Task ${id} [${priority === undefined ? '<default>' : priority}]`,
@@ -94,7 +95,8 @@ describe('SchedulerPostTask', () => {
9495
});
9596
};
9697

97-
scheduler.yield = function ({priority, signal}) {
98+
scheduler.yield = function ({signal}) {
99+
const {priority} = signal;
98100
const id = idCounter++;
99101
log(`Yield ${id} [${priority === undefined ? '<default>' : priority}]`);
100102
const controller = signal._controller;
@@ -111,8 +113,8 @@ describe('SchedulerPostTask', () => {
111113
};
112114

113115
global.TaskController = class TaskController {
114-
constructor() {
115-
this.signal = {_controller: this};
116+
constructor({priority}) {
117+
this.signal = {_controller: this, priority};
116118
}
117119
abort() {
118120
const task = taskQueue.get(this);

packages/scheduler/src/forks/SchedulerPostTask.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type {PriorityLevel} from '../SchedulerPriorities';
1111

1212
declare class TaskController {
13-
constructor(priority?: string): TaskController;
13+
constructor(options?: {priority?: string}): TaskController;
1414
signal: mixed;
1515
abort(): void;
1616
}
@@ -95,9 +95,8 @@ export function unstable_scheduleCallback<T>(
9595
break;
9696
}
9797

98-
const controller = new TaskController();
98+
const controller = new TaskController({priority: postTaskPriority});
9999
const postTaskOptions = {
100-
priority: postTaskPriority,
101100
delay: typeof options === 'object' && options !== null ? options.delay : 0,
102101
signal: controller.signal,
103102
};
@@ -130,9 +129,10 @@ function runTask<T>(
130129
if (typeof result === 'function') {
131130
// Assume this is a continuation
132131
const continuation: SchedulerCallback<T> = (result: any);
133-
const continuationController = new TaskController();
134-
const continuationOptions = {
132+
const continuationController = new TaskController({
135133
priority: postTaskPriority,
134+
});
135+
const continuationOptions = {
136136
signal: continuationController.signal,
137137
};
138138
// Update the original callback node's controller, since even though we're

0 commit comments

Comments
 (0)