Skip to content

Commit df36085

Browse files
authored
Merge pull request microsoft#185389 from microsoft/tyriar/fname__calls
Reduce unnecessary calls to PtyService
2 parents 7f5de39 + 99e380d commit df36085

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

src/vs/workbench/contrib/terminal/browser/remotePty.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,8 @@ import { RemoteTerminalChannelClient } from 'vs/workbench/contrib/terminal/commo
1414
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
1515

1616
export class RemotePty extends Disposable implements ITerminalChildProcess {
17-
private readonly _onProcessData = this._register(new Emitter<string | IProcessDataEvent>());
18-
readonly onProcessData = this._onProcessData.event;
19-
private readonly _onProcessReady = this._register(new Emitter<IProcessReadyEvent>());
20-
readonly onProcessReady = this._onProcessReady.event;
21-
private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>());
22-
readonly onDidChangeProperty = this._onDidChangeProperty.event;
23-
private readonly _onProcessExit = this._register(new Emitter<number | undefined>());
24-
readonly onProcessExit = this._onProcessExit.event;
25-
private readonly _onRestoreCommands = this._register(new Emitter<ISerializedCommandDetectionCapability>());
26-
readonly onRestoreCommands = this._onRestoreCommands.event;
27-
28-
private _startBarrier: Barrier;
29-
30-
private _inReplay = false;
31-
32-
private _properties: IProcessPropertyMap = {
17+
private readonly _startBarrier: Barrier;
18+
private readonly _properties: IProcessPropertyMap = {
3319
cwd: '',
3420
initialCwd: '',
3521
fixedDimensions: { cols: undefined, rows: undefined },
@@ -41,15 +27,27 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
4127
failedShellIntegrationActivation: false,
4228
usedShellIntegrationInjection: undefined
4329
};
30+
private readonly _lastDimensions: { cols: number; rows: number } = { cols: -1, rows: -1 };
4431

45-
get id(): number { return this._id; }
32+
private _inReplay = false;
33+
34+
private readonly _onProcessData = this._register(new Emitter<string | IProcessDataEvent>());
35+
readonly onProcessData = this._onProcessData.event;
36+
private readonly _onProcessReady = this._register(new Emitter<IProcessReadyEvent>());
37+
readonly onProcessReady = this._onProcessReady.event;
38+
private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>());
39+
readonly onDidChangeProperty = this._onDidChangeProperty.event;
40+
private readonly _onProcessExit = this._register(new Emitter<number | undefined>());
41+
readonly onProcessExit = this._onProcessExit.event;
42+
private readonly _onRestoreCommands = this._register(new Emitter<ISerializedCommandDetectionCapability>());
43+
readonly onRestoreCommands = this._onRestoreCommands.event;
4644

4745
constructor(
48-
private _id: number,
46+
readonly id: number,
4947
readonly shouldPersist: boolean,
5048
private readonly _remoteTerminalChannel: RemoteTerminalChannelClient,
51-
private readonly _remoteAgentService: IRemoteAgentService,
52-
private readonly _logService: ILogService
49+
@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
50+
@ILogService private readonly _logService: ILogService
5351
) {
5452
super();
5553
this._startBarrier = new Barrier();
@@ -63,9 +61,9 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
6361
throw new Error('Could not fetch remote environment');
6462
}
6563

66-
this._logService.trace('Spawning remote agent process', { terminalId: this._id });
64+
this._logService.trace('Spawning remote agent process', { terminalId: this.id });
6765

68-
const startResult = await this._remoteTerminalChannel.start(this._id);
66+
const startResult = await this._remoteTerminalChannel.start(this.id);
6967

7068
if (startResult && 'message' in startResult) {
7169
// An error occurred
@@ -83,7 +81,7 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
8381

8482
shutdown(immediate: boolean): void {
8583
this._startBarrier.wait().then(_ => {
86-
this._remoteTerminalChannel.shutdown(this._id, immediate);
84+
this._remoteTerminalChannel.shutdown(this.id, immediate);
8785
});
8886
}
8987

@@ -93,17 +91,18 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
9391
}
9492

9593
this._startBarrier.wait().then(_ => {
96-
this._remoteTerminalChannel.input(this._id, data);
94+
this._remoteTerminalChannel.input(this.id, data);
9795
});
9896
}
9997

10098
resize(cols: number, rows: number): void {
101-
if (this._inReplay) {
99+
if (this._inReplay || this._lastDimensions.cols === cols && this._lastDimensions.rows === rows) {
102100
return;
103101
}
104102
this._startBarrier.wait().then(_ => {
105-
106-
this._remoteTerminalChannel.resize(this._id, cols, rows);
103+
this._lastDimensions.cols = cols;
104+
this._lastDimensions.rows = rows;
105+
this._remoteTerminalChannel.resize(this.id, cols, rows);
107106
});
108107
}
109108

@@ -125,12 +124,12 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
125124
}
126125

127126
this._startBarrier.wait().then(_ => {
128-
this._remoteTerminalChannel.acknowledgeDataEvent(this._id, charCount);
127+
this._remoteTerminalChannel.acknowledgeDataEvent(this.id, charCount);
129128
});
130129
}
131130

132131
async setUnicodeVersion(version: '6' | '11'): Promise<void> {
133-
return this._remoteTerminalChannel.setUnicodeVersion(this._id, version);
132+
return this._remoteTerminalChannel.setUnicodeVersion(this.id, version);
134133
}
135134

136135
async getInitialCwd(): Promise<string> {
@@ -142,11 +141,11 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
142141
}
143142

144143
async refreshProperty<T extends ProcessPropertyType>(type: T): Promise<IProcessPropertyMap[T]> {
145-
return this._remoteTerminalChannel.refreshProperty(this._id, type);
144+
return this._remoteTerminalChannel.refreshProperty(this.id, type);
146145
}
147146

148147
async updateProperty<T extends ProcessPropertyType>(type: T, value: IProcessPropertyMap[T]): Promise<void> {
149-
return this._remoteTerminalChannel.updateProperty(this._id, type, value);
148+
return this._remoteTerminalChannel.updateProperty(this.id, type, value);
150149
}
151150

152151
handleData(e: string | IProcessDataEvent) {
@@ -156,7 +155,7 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
156155
this._onProcessExit.fire(e);
157156
}
158157
processBinary(e: string): Promise<void> {
159-
return this._remoteTerminalChannel.processBinary(this._id, e);
158+
return this._remoteTerminalChannel.processBinary(this.id, e);
160159
}
161160
handleReady(e: IProcessReadyEvent) {
162161
this._onProcessReady.fire(e);
@@ -202,7 +201,7 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
202201
}
203202

204203
handleOrphanQuestion() {
205-
this._remoteTerminalChannel.orphanQuestionReply(this._id);
204+
this._remoteTerminalChannel.orphanQuestionReply(this.id);
206205
}
207206

208207
async getLatency(): Promise<number> {

src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class RemoteTerminalBackend extends BaseTerminalBackend implements ITerminalBack
6363
readonly remoteAuthority: string | undefined,
6464
private readonly _remoteTerminalChannel: RemoteTerminalChannelClient,
6565
@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
66+
@IInstantiationService private readonly _instantiationService: IInstantiationService,
6667
@ILogService logService: ILogService,
6768
@ICommandService private readonly _commandService: ICommandService,
6869
@IStorageService private readonly _storageService: IStorageService,
@@ -221,7 +222,7 @@ class RemoteTerminalBackend extends BaseTerminalBackend implements ITerminalBack
221222
rows,
222223
unicodeVersion
223224
);
224-
const pty = new RemotePty(result.persistentTerminalId, shouldPersist, this._remoteTerminalChannel, this._remoteAgentService, this._logService);
225+
const pty = this._instantiationService.createInstance(RemotePty, result.persistentTerminalId, shouldPersist, this._remoteTerminalChannel);
225226
this._ptys.set(result.persistentTerminalId, pty);
226227
return pty;
227228
}
@@ -233,7 +234,7 @@ class RemoteTerminalBackend extends BaseTerminalBackend implements ITerminalBack
233234

234235
try {
235236
await this._remoteTerminalChannel.attachToProcess(id);
236-
const pty = new RemotePty(id, true, this._remoteTerminalChannel, this._remoteAgentService, this._logService);
237+
const pty = this._instantiationService.createInstance(RemotePty, id, true, this._remoteTerminalChannel);
237238
this._ptys.set(id, pty);
238239
return pty;
239240
} catch (e) {

src/vs/workbench/contrib/terminal/electron-sandbox/localPty.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability } fro
1414
* created on the local pty host.
1515
*/
1616
export class LocalPty extends Disposable implements ITerminalChildProcess {
17-
private _inReplay = false;
18-
private _properties: IProcessPropertyMap = {
17+
private readonly _properties: IProcessPropertyMap = {
1918
cwd: '',
2019
initialCwd: '',
2120
fixedDimensions: { cols: undefined, rows: undefined },
@@ -27,6 +26,10 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
2726
failedShellIntegrationActivation: false,
2827
usedShellIntegrationInjection: undefined
2928
};
29+
private readonly _lastDimensions: { cols: number; rows: number } = { cols: -1, rows: -1 };
30+
31+
private _inReplay = false;
32+
3033
private readonly _onProcessData = this._register(new Emitter<IProcessDataEvent | string>());
3134
readonly onProcessData = this._onProcessData.event;
3235
private readonly _onProcessReplay = this._register(new Emitter<IPtyHostProcessReplayEvent>());
@@ -70,9 +73,11 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
7073
this._localPtyService.input(this.id, data);
7174
}
7275
resize(cols: number, rows: number): void {
73-
if (this._inReplay) {
76+
if (this._inReplay || this._lastDimensions.cols === cols && this._lastDimensions.rows === rows) {
7477
return;
7578
}
79+
this._lastDimensions.cols = cols;
80+
this._lastDimensions.rows = rows;
7681
this._localPtyService.resize(this.id, cols, rows);
7782
}
7883
async clearBuffer(): Promise<void> {

src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { mark, PerformanceMark } from 'vs/base/common/performance';
3636
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
3737
import { DeferredPromise } from 'vs/base/common/async';
3838
import { IStatusbarService } from 'vs/workbench/services/statusbar/browser/statusbar';
39+
import { memoize } from 'vs/base/common/decorators';
3940

4041
export class LocalTerminalBackendContribution implements IWorkbenchContribution {
4142
constructor(
@@ -236,6 +237,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
236237
return this._localPtyService.getProfiles?.(this._workspaceContextService.getWorkspace().id, profiles, defaultProfile, includeDetectedProfiles) || [];
237238
}
238239

240+
@memoize
239241
async getEnvironment(): Promise<IProcessEnvironment> {
240242
return this._proxy.getEnvironment();
241243
}

0 commit comments

Comments
 (0)