Skip to content
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

Enable terminal event batching from ptyHost #117268

Merged
merged 11 commits into from
Mar 26, 2021
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