Skip to content

Commit adafd26

Browse files
authored
Merge pull request microsoft#186041 from microsoft/tyriar/185393_4
Improve pty host startup marks/traces, revive terminal procs in parallel
2 parents ef4cd64 + 4350ccd commit adafd26

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

src/vs/platform/terminal/node/ptyService.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -204,36 +204,42 @@ export class PtyService extends Disposable implements IPtyService {
204204

205205
@traceRpc
206206
async reviveTerminalProcesses(state: ISerializedTerminalState[], dateTimeFormatLocale: string) {
207+
const promises: Promise<void>[] = [];
207208
for (const terminal of state) {
208-
const restoreMessage = localize('terminal-history-restored', "History restored");
209-
// TODO: We may at some point want to show date information in a hover via a custom sequence:
210-
// new Date(terminal.timestamp).toLocaleDateString(dateTimeFormatLocale)
211-
// new Date(terminal.timestamp).toLocaleTimeString(dateTimeFormatLocale)
212-
const newId = await this.createProcess(
213-
{
214-
...terminal.shellLaunchConfig,
215-
cwd: terminal.processDetails.cwd,
216-
color: terminal.processDetails.color,
217-
icon: terminal.processDetails.icon,
218-
name: terminal.processDetails.titleSource === TitleEventSource.Api ? terminal.processDetails.title : undefined,
219-
initialText: terminal.replayEvent.events[0].data + formatMessageForTerminal(restoreMessage, { loudFormatting: true })
220-
},
221-
terminal.processDetails.cwd,
222-
terminal.replayEvent.events[0].cols,
223-
terminal.replayEvent.events[0].rows,
224-
terminal.unicodeVersion,
225-
terminal.processLaunchConfig.env,
226-
terminal.processLaunchConfig.executableEnv,
227-
terminal.processLaunchConfig.options,
228-
true,
229-
terminal.processDetails.workspaceId,
230-
terminal.processDetails.workspaceName,
231-
true,
232-
terminal.replayEvent.events[0].data
233-
);
234-
// Don't start the process here as there's no terminal to answer CPR
235-
this._revivedPtyIdMap.set(terminal.id, { newId, state: terminal });
209+
promises.push(this._reviveTerminalProcess(terminal));
236210
}
211+
await Promise.all(promises);
212+
}
213+
214+
private async _reviveTerminalProcess(terminal: ISerializedTerminalState): Promise<void> {
215+
const restoreMessage = localize('terminal-history-restored', "History restored");
216+
// TODO: We may at some point want to show date information in a hover via a custom sequence:
217+
// new Date(terminal.timestamp).toLocaleDateString(dateTimeFormatLocale)
218+
// new Date(terminal.timestamp).toLocaleTimeString(dateTimeFormatLocale)
219+
const newId = await this.createProcess(
220+
{
221+
...terminal.shellLaunchConfig,
222+
cwd: terminal.processDetails.cwd,
223+
color: terminal.processDetails.color,
224+
icon: terminal.processDetails.icon,
225+
name: terminal.processDetails.titleSource === TitleEventSource.Api ? terminal.processDetails.title : undefined,
226+
initialText: terminal.replayEvent.events[0].data + formatMessageForTerminal(restoreMessage, { loudFormatting: true })
227+
},
228+
terminal.processDetails.cwd,
229+
terminal.replayEvent.events[0].cols,
230+
terminal.replayEvent.events[0].rows,
231+
terminal.unicodeVersion,
232+
terminal.processLaunchConfig.env,
233+
terminal.processLaunchConfig.executableEnv,
234+
terminal.processLaunchConfig.options,
235+
true,
236+
terminal.processDetails.workspaceId,
237+
terminal.processDetails.workspaceName,
238+
true,
239+
terminal.replayEvent.events[0].data
240+
);
241+
// Don't start the process here as there's no terminal to answer CPR
242+
this._revivedPtyIdMap.set(terminal.id, { newId, state: terminal });
237243
}
238244

239245
@traceRpc
@@ -506,7 +512,6 @@ export class PtyService extends Disposable implements IPtyService {
506512
if (layout) {
507513
const expandedTabs = await Promise.all(layout.tabs.map(async tab => this._expandTerminalTab(tab)));
508514
const tabs = expandedTabs.filter(t => t.terminals.length > 0);
509-
this._logService.trace('PtyService.getTerminalLayoutInfo result', tabs);
510515
performance.mark('code/didGetTerminalLayoutInfo');
511516
return { tabs };
512517
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
9393
// The pty host should not get launched until the first window restored phase
9494
await this._lifecycleService.when(LifecyclePhase.Restored);
9595

96-
mark('code/willConnectPtyHost');
96+
mark('code/terminal/willConnectPtyHost');
9797
this._logService.trace('Renderer->PtyHost#connect: before acquirePort');
9898
acquirePort('vscode:createPtyHostMessageChannel', 'vscode:createPtyHostMessageChannelResult').then(port => {
99-
mark('code/didConnectPtyHost');
99+
mark('code/terminal/didConnectPtyHost');
100100
this._logService.trace('Renderer->PtyHost#connect: connection established');
101101
// There are two connections to the pty host; one to the regular shared process
102102
// _localPtyService, and one directly via message port _ptyHostDirectProxy. The former is
@@ -278,18 +278,24 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
278278

279279
// Re-resolve the environments and replace it on the state so local terminals use a fresh
280280
// environment
281+
mark('code/terminal/willGetReviveEnvironments');
281282
for (const state of parsed) {
282283
const freshEnv = await this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig);
283284
state.processLaunchConfig.env = freshEnv;
284285
}
286+
mark('code/terminal/didGetReviveEnvironments');
285287

288+
mark('code/terminal/willReviveTerminalProcesses');
286289
await this._localPtyService.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
290+
mark('code/terminal/didReviveTerminalProcesses');
287291
this._storageService.remove(TerminalStorageKeys.TerminalBufferState, StorageScope.WORKSPACE);
288292
// If reviving processes, send the terminal layout info back to the pty host as it
289293
// will not have been persisted on application exit
290294
const layoutInfo = this._storageService.get(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
291295
if (layoutInfo) {
296+
mark('code/terminal/willSetTerminalLayoutInfo');
292297
await this._localPtyService.setTerminalLayoutInfo(JSON.parse(layoutInfo));
298+
mark('code/terminal/didSetTerminalLayoutInfo');
293299
this._storageService.remove(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
294300
}
295301
} catch {

0 commit comments

Comments
 (0)