Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/CoreTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
this.register(forwardEvent(this._bufferService.onResize, this._onResize));
this.register(forwardEvent(this.coreService.onData, this._onData));
this.register(forwardEvent(this.coreService.onBinary, this._onBinary));
this.register(this.coreService.onUserInput(() => this._writeBuffer.handleUserInput()));
this.register(this.optionsService.onOptionChange(key => this._updateOptions(key)));
this.register(this._bufferService.onScroll(event => {
this._onScroll.fire({ position: this._bufferService.buffer.ydisp, source: ScrollSource.TERMINAL });
Expand Down
15 changes: 14 additions & 1 deletion src/common/input/WriteBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ export class WriteBuffer {
private _bufferOffset = 0;
private _isSyncWriting = false;
private _syncCalls = 0;
private _didUserInput = false;
public get onWriteParsed(): IEvent<void> { return this._onWriteParsed.event; }
private _onWriteParsed = new EventEmitter<void>();

constructor(private _action: (data: string | Uint8Array, promiseResult?: boolean) => void | Promise<boolean>) { }

public handleUserInput(): void {
this._didUserInput = true;
}

/**
* @deprecated Unreliable, to be removed soon.
*/
Expand Down Expand Up @@ -99,7 +104,15 @@ export class WriteBuffer {
// schedule chunk processing for next event loop run
if (!this._writeBuffer.length) {
this._bufferOffset = 0;
queueMicrotask(() => this._innerWrite());
// If this is the first write call after the user has done some input,
// parse it immediately in an upcoming microtask to minimize reduce input,
// otherwise schedule for the next event
if (this._didUserInput) {
this._didUserInput = false;
queueMicrotask(() => this._innerWrite());
Copy link
Copy Markdown
Member

@jerch jerch Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If latency is your main concern here - I think we can call this._innerWrite() directly here? (after pulling the last 3 lines of the method before the call) I dont see a reason for microtask delegation here, but there is a chance I am overlooking something.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right, this made more sense in the previous iteration when I was relying on data length instead of the user input signal, will change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to duplicate some calls to make this happen, that's one of the reasons why it was microtask

} else {
setTimeout(() => this._innerWrite());
}
}

this._pendingData += data.length;
Expand Down