Apply idle optimizations throughout code base
Summary: See explanation in parent diff, make sure the idler is used efficiently, instead of wasting a lot of CPU creating a new callstack every time `idle` is called. Also fixed that cancelled idlers could result in an _uncaught_ exception Reviewed By: nikoant Differential Revision: D19158593 fbshipit-source-id: 0be505a74c374e0ca6ee0e79b1f1e98ac9b80467
This commit is contained in:
committed by
Facebook Github Bot
parent
0a5df48639
commit
bc36c1607d
@@ -25,7 +25,7 @@ export class Idler implements BaseIdler {
|
|||||||
return this.kill || performance.now() - this.lastIdle > this.interval;
|
return this.kill || performance.now() - this.lastIdle > this.interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
idle(): Promise<void> {
|
async idle(): Promise<void> {
|
||||||
if (this.kill) {
|
if (this.kill) {
|
||||||
throw new CancelledPromiseError('Idler got killed');
|
throw new CancelledPromiseError('Idler got killed');
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ export class Idler implements BaseIdler {
|
|||||||
this.lastIdle = now;
|
this.lastIdle = now;
|
||||||
return new Promise(resolve => setTimeout(resolve, 0));
|
return new Promise(resolve => setTimeout(resolve, 0));
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export async function makeObjectSerializable(
|
|||||||
let prevStackLength = stack.length;
|
let prevStackLength = stack.length;
|
||||||
let accumulator = prevStackLength;
|
let accumulator = prevStackLength;
|
||||||
while (stack.length > 0) {
|
while (stack.length > 0) {
|
||||||
if (idler) {
|
if (idler && idler.shouldIdle()) {
|
||||||
await idler.idle();
|
await idler.idle();
|
||||||
}
|
}
|
||||||
const element = stack[stack.length - 1];
|
const element = stack[stack.length - 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user