Skip to content

Commit

Permalink
Enable terminal event batching from ptyHost (#117268)
Browse files Browse the repository at this point in the history
* fix #116468
Co-authored-by: Daniel Imms <[email protected]>
  • Loading branch information
meganrogge authored and jrieken committed Mar 29, 2021
1 parent 3b10a59 commit 2a60d7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/vs/platform/terminal/common/terminalDataBuffering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ export class TerminalDataBufferer implements IDisposable {
let buffer = this._terminalBufferMap.get(id);
if (buffer) {
buffer.data.push(data);

return;
}

const timeoutId = setTimeout(() => this._flushBuffer(id), throttleBy);
const timeoutId = setTimeout(() => this.flushBuffer(id), throttleBy);
buffer = {
data: [data],
timeoutId: timeoutId,
dispose: () => {
clearTimeout(timeoutId);
this._flushBuffer(id);
this.flushBuffer(id);
disposable.dispose();
}
};
Expand All @@ -57,7 +56,7 @@ export class TerminalDataBufferer implements IDisposable {
}
}

private _flushBuffer(id: number): void {
flushBuffer(id: number): void {
const buffer = this._terminalBufferMap.get(id);
if (buffer) {
this._terminalBufferMap.delete(id);
Expand Down
29 changes: 13 additions & 16 deletions src/vs/platform/terminal/node/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TerminalRecorder } from 'vs/platform/terminal/common/terminalRecorder';
import { TerminalProcess } from 'vs/platform/terminal/node/terminalProcess';
import { ISetTerminalLayoutInfoArgs, ITerminalTabLayoutInfoDto, IProcessDetails, IGetTerminalLayoutInfoArgs, IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/terminalProcess';
import { ILogService } from 'vs/platform/log/common/log';
import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering';

type WorkspaceId = string;

Expand Down Expand Up @@ -224,7 +225,7 @@ export class PtyService extends Disposable implements IPtyService {

export class PersistentTerminalProcess extends Disposable {

// private readonly _bufferer: TerminalDataBufferer;
private readonly _bufferer: TerminalDataBufferer;

private readonly _pendingCommands = new Map<number, { resolve: (data: any) => void; reject: (err: any) => void; }>();

Expand Down Expand Up @@ -282,28 +283,21 @@ export class PersistentTerminalProcess extends Disposable {
this.shutdown(true);
}, LocalReconnectConstants.ReconnectionShortGraceTime));

// TODO: Bring back bufferer
// this._bufferer = new TerminalDataBufferer((id, data) => {
// const ev: IPtyHostProcessDataEvent = {
// type: 'data',
// data: data
// };
// this._events.fire(ev);
// });

this._register(this._terminalProcess.onProcessReady(e => {
this._pid = e.pid;
this._cwd = e.cwd;
this._onProcessReady.fire(e);
}));
this._register(this._terminalProcess.onProcessTitleChanged(e => this._onProcessTitleChanged.fire(e)));
this._register(this._terminalProcess.onProcessShellTypeChanged(e => this._onProcessShellTypeChanged.fire(e)));
// Buffer data events to reduce the amount of messages going to the renderer
// this._register(this._bufferer.startBuffering(this._persistentProcessId, this._terminalProcess.onProcessData));
this._register(this._terminalProcess.onProcessData(e => this._recorder.recordData(e)));
this._register(this._terminalProcess.onProcessExit(exitCode => {
// this._bufferer.stopBuffering(this._persistentProcessId);
}));

// Data buffering to reduce the amount of messages going to the renderer
this._bufferer = new TerminalDataBufferer((_, data) => this._onProcessData.fire({ data: data, sync: true }));
this._register(this._bufferer.startBuffering(this._persistentProcessId, this._terminalProcess.onProcessData));
this._register(this._terminalProcess.onProcessExit(() => this._bufferer.stopBuffering(this._persistentProcessId)));

// Data recording for reconnect
this._register(this.onProcessData(e => this._recorder.recordData(e.data)));
}

attach(): void {
Expand Down Expand Up @@ -348,6 +342,9 @@ export class PersistentTerminalProcess extends Disposable {
return;
}
this._recorder.recordResize(cols, rows);

// Buffered events should flush when a resize occurs
this._bufferer.flushBuffer(this._persistentProcessId);
return this._terminalProcess.resize(cols, rows);
}
acknowledgeDataEvent(charCount: number): void {
Expand Down

0 comments on commit 2a60d7f

Please sign in to comment.