Skip to content

Commit 477558f

Browse files
authored
Merge pull request microsoft#186681 from microsoft/tyriar/186671
Various speed ups to terminal reconnection
2 parents 77e84b6 + 885697b commit 477558f

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,12 @@ export class TerminalService implements ITerminalService {
298298
const instances = await this._reconnectedTerminalGroups?.then(groups => groups.map(e => e.terminalInstances).flat()) ?? [];
299299
await Promise.all(instances.map(e => new Promise<void>(r => Event.once(e.onProcessReplayComplete)(r))));
300300
mark('code/terminal/didReplay');
301-
for (const backend of this._terminalInstanceService.getRegisteredBackends()) {
302-
mark('code/terminal/willGetPerformanceMarks');
301+
mark('code/terminal/willGetPerformanceMarks');
302+
await Promise.all(Array.from(this._terminalInstanceService.getRegisteredBackends()).map(async backend => {
303303
this._timerService.setPerformanceMarks(backend.remoteAuthority === undefined ? 'localPtyHost' : 'remotePtyHost', await backend.getPerformanceMarks());
304-
mark('code/terminal/didGetPerformanceMarks');
305304
backend.setConnected();
306-
}
305+
}));
306+
mark('code/terminal/didGetPerformanceMarks');
307307
this._whenConnected.complete();
308308
});
309309

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
8787
this._proxy = ProxyChannel.toService<IPtyService>(getDelayedChannel(clientEventually.p.then(client => client.getChannel(TerminalIpcChannels.PtyHostWindow))));
8888
this._connectToDirectProxy(clientEventually);
8989
}));
90+
91+
// Eagerly fetch the backend's environment for memoization
92+
this.getEnvironment();
9093
}
9194

9295
private async _connectToDirectProxy(clientEventually: DeferredPromise<MessagePortClient>): Promise<void> {
@@ -242,6 +245,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
242245
return this._proxy.getEnvironment();
243246
}
244247

248+
@memoize
245249
async getShellEnvironment(): Promise<IProcessEnvironment> {
246250
return this._shellEnvironmentService.getShellEnv();
247251
}
@@ -279,22 +283,24 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
279283
// Re-resolve the environments and replace it on the state so local terminals use a fresh
280284
// environment
281285
mark('code/terminal/willGetReviveEnvironments');
282-
for (const state of parsed) {
283-
const freshEnv = await this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig);
284-
state.processLaunchConfig.env = freshEnv;
285-
}
286+
await Promise.all(parsed.map(state => new Promise<void>(r => {
287+
this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig).then(freshEnv => {
288+
state.processLaunchConfig.env = freshEnv;
289+
r();
290+
});
291+
})));
286292
mark('code/terminal/didGetReviveEnvironments');
287293

288294
mark('code/terminal/willReviveTerminalProcesses');
289-
await this._localPtyService.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
295+
await this._proxy.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
290296
mark('code/terminal/didReviveTerminalProcesses');
291297
this._storageService.remove(TerminalStorageKeys.TerminalBufferState, StorageScope.WORKSPACE);
292298
// If reviving processes, send the terminal layout info back to the pty host as it
293299
// will not have been persisted on application exit
294300
const layoutInfo = this._storageService.get(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
295301
if (layoutInfo) {
296302
mark('code/terminal/willSetTerminalLayoutInfo');
297-
await this._localPtyService.setTerminalLayoutInfo(JSON.parse(layoutInfo));
303+
await this._proxy.setTerminalLayoutInfo(JSON.parse(layoutInfo));
298304
mark('code/terminal/didSetTerminalLayoutInfo');
299305
this._storageService.remove(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
300306
}
@@ -303,7 +309,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
303309
}
304310
}
305311

306-
return this._localPtyService.getTerminalLayoutInfo(layoutArgs);
312+
return this._proxy.getTerminalLayoutInfo(layoutArgs);
307313
}
308314

309315
private async _resolveEnvironmentForRevive(variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise<IProcessEnvironment> {

0 commit comments

Comments
 (0)