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

Various speed ups to terminal reconnection #186681

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ export class TerminalService implements ITerminalService {
const instances = await this._reconnectedTerminalGroups?.then(groups => groups.map(e => e.terminalInstances).flat()) ?? [];
await Promise.all(instances.map(e => new Promise<void>(r => Event.once(e.onProcessReplayComplete)(r))));
mark('code/terminal/didReplay');
for (const backend of this._terminalInstanceService.getRegisteredBackends()) {
mark('code/terminal/willGetPerformanceMarks');
mark('code/terminal/willGetPerformanceMarks');
await Promise.all(Array.from(this._terminalInstanceService.getRegisteredBackends()).map(async backend => {
this._timerService.setPerformanceMarks(backend.remoteAuthority === undefined ? 'localPtyHost' : 'remotePtyHost', await backend.getPerformanceMarks());
mark('code/terminal/didGetPerformanceMarks');
backend.setConnected();
}
}));
mark('code/terminal/didGetPerformanceMarks');
this._whenConnected.complete();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
this._proxy = ProxyChannel.toService<IPtyService>(getDelayedChannel(clientEventually.p.then(client => client.getChannel(TerminalIpcChannels.PtyHostWindow))));
this._connectToDirectProxy(clientEventually);
}));

// Eagerly fetch the backend's environment for memoization
this.getEnvironment();
}

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

@memoize
async getShellEnvironment(): Promise<IProcessEnvironment> {
return this._shellEnvironmentService.getShellEnv();
}
Expand Down Expand Up @@ -279,22 +283,24 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
// Re-resolve the environments and replace it on the state so local terminals use a fresh
// environment
mark('code/terminal/willGetReviveEnvironments');
for (const state of parsed) {
const freshEnv = await this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig);
state.processLaunchConfig.env = freshEnv;
}
await Promise.all(parsed.map(state => new Promise<void>(r => {
this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig).then(freshEnv => {
state.processLaunchConfig.env = freshEnv;
r();
});
})));
mark('code/terminal/didGetReviveEnvironments');

mark('code/terminal/willReviveTerminalProcesses');
await this._localPtyService.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
await this._proxy.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
mark('code/terminal/didReviveTerminalProcesses');
this._storageService.remove(TerminalStorageKeys.TerminalBufferState, StorageScope.WORKSPACE);
// If reviving processes, send the terminal layout info back to the pty host as it
// will not have been persisted on application exit
const layoutInfo = this._storageService.get(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
if (layoutInfo) {
mark('code/terminal/willSetTerminalLayoutInfo');
await this._localPtyService.setTerminalLayoutInfo(JSON.parse(layoutInfo));
await this._proxy.setTerminalLayoutInfo(JSON.parse(layoutInfo));
mark('code/terminal/didSetTerminalLayoutInfo');
this._storageService.remove(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
}
Expand All @@ -303,7 +309,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
}
}

return this._localPtyService.getTerminalLayoutInfo(layoutArgs);
return this._proxy.getTerminalLayoutInfo(layoutArgs);
}

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