-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Optimize critical I/O path for input latency #4145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ export class WriteBuffer { | |
| // schedule chunk processing for next event loop run | ||
| if (!this._writeBuffer.length) { | ||
| this._bufferOffset = 0; | ||
| setTimeout(() => this._innerWrite()); | ||
| queueMicrotask(() => this._innerWrite()); | ||
| } | ||
|
|
||
| this._pendingData += data.length; | ||
|
|
@@ -217,7 +217,7 @@ export class WriteBuffer { | |
| this._callbacks = this._callbacks.slice(this._bufferOffset); | ||
| this._bufferOffset = 0; | ||
| } | ||
| setTimeout(() => this._innerWrite()); | ||
| queueMicrotask(() => this._innerWrite()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not so sure about There are more edge cases linked to direct microtask usage - imho chrome and firefox prioritize them differently (dont remember the details atm).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opps. You're right, will fix
I didn't test in Firefox but this should only matter if queueMicrotask ends up slower than setTimeout which I think would be against the spec? |
||
| } else { | ||
| this._writeBuffer.length = 0; | ||
| this._callbacks.length = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be safe with
queueMicrotask- reason: this code path is only entered, if the write queue was empty before, which guarantees, that there happened a screen refresh before.