Skip to content

Commit 2a74e7d

Browse files
committed
perf - resolve paths in parallel on startup
1 parent 4247dde commit 2a74e7d

File tree

1 file changed

+56
-51
lines changed

1 file changed

+56
-51
lines changed

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -769,38 +769,42 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
769769
}
770770

771771
private async doExtractPathsFromAPI(openConfig: IOpenConfiguration): Promise<IPathToOpen[]> {
772-
const pathsToOpen: IPathToOpen[] = [];
773-
const pathResolveOptions: IPathResolveOptions = { gotoLineMode: openConfig.gotoLineMode, remoteAuthority: openConfig.remoteAuthority };
774-
for (const pathToOpen of coalesce(openConfig.urisToOpen || [])) {
772+
const pathResolveOptions: IPathResolveOptions = {
773+
gotoLineMode: openConfig.gotoLineMode,
774+
remoteAuthority: openConfig.remoteAuthority
775+
};
776+
777+
const pathsToOpen = await Promise.all(coalesce(openConfig.urisToOpen || []).map(async pathToOpen => {
775778
const path = await this.resolveOpenable(pathToOpen, pathResolveOptions);
776779

777780
// Path exists
778781
if (path) {
779782
path.label = pathToOpen.label;
780-
pathsToOpen.push(path);
783+
784+
return path;
781785
}
782786

783787
// Path does not exist: show a warning box
784-
else {
785-
const uri = this.resourceFromOpenable(pathToOpen);
786-
787-
const options: MessageBoxOptions = {
788-
title: this.productService.nameLong,
789-
type: 'info',
790-
buttons: [mnemonicButtonLabel(localize({ key: 'ok', comment: ['&& denotes a mnemonic'] }, "&&OK"))],
791-
defaultId: 0,
792-
message: uri.scheme === Schemas.file ? localize('pathNotExistTitle', "Path does not exist") : localize('uriInvalidTitle', "URI can not be opened"),
793-
detail: uri.scheme === Schemas.file ?
794-
localize('pathNotExistDetail', "The path '{0}' does not exist on this computer.", getPathLabel(uri, { os: OS, tildify: this.environmentMainService })) :
795-
localize('uriInvalidDetail', "The URI '{0}' is not valid and can not be opened.", uri.toString(true)),
796-
noLink: true
797-
};
788+
const uri = this.resourceFromOpenable(pathToOpen);
789+
790+
const options: MessageBoxOptions = {
791+
title: this.productService.nameLong,
792+
type: 'info',
793+
buttons: [mnemonicButtonLabel(localize({ key: 'ok', comment: ['&& denotes a mnemonic'] }, "&&OK"))],
794+
defaultId: 0,
795+
message: uri.scheme === Schemas.file ? localize('pathNotExistTitle', "Path does not exist") : localize('uriInvalidTitle', "URI can not be opened"),
796+
detail: uri.scheme === Schemas.file ?
797+
localize('pathNotExistDetail', "The path '{0}' does not exist on this computer.", getPathLabel(uri, { os: OS, tildify: this.environmentMainService })) :
798+
localize('uriInvalidDetail', "The URI '{0}' is not valid and can not be opened.", uri.toString(true)),
799+
noLink: true
800+
};
801+
802+
this.dialogMainService.showMessageBox(options, withNullAsUndefined(BrowserWindow.getFocusedWindow()));
798803

799-
this.dialogMainService.showMessageBox(options, withNullAsUndefined(BrowserWindow.getFocusedWindow()));
800-
}
801-
}
804+
return undefined;
805+
}));
802806

803-
return pathsToOpen;
807+
return coalesce(pathsToOpen);
804808
}
805809

806810
private async doExtractPathsFromCLI(cli: NativeParsedArgs): Promise<IPath[]> {
@@ -820,39 +824,39 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
820824
// folder uris
821825
const folderUris = cli['folder-uri'];
822826
if (folderUris) {
823-
for (const rawFolderUri of folderUris) {
827+
const resolvedFolderUris = await Promise.all(folderUris.map(rawFolderUri => {
824828
const folderUri = this.cliArgToUri(rawFolderUri);
825-
if (folderUri) {
826-
const path = await this.resolveOpenable({ folderUri }, pathResolveOptions);
827-
if (path) {
828-
pathsToOpen.push(path);
829-
}
829+
if (!folderUri) {
830+
return undefined;
830831
}
831-
}
832+
833+
return this.resolveOpenable({ folderUri }, pathResolveOptions);
834+
}));
835+
836+
pathsToOpen.push(...coalesce(resolvedFolderUris));
832837
}
833838

834839
// file uris
835840
const fileUris = cli['file-uri'];
836841
if (fileUris) {
837-
for (const rawFileUri of fileUris) {
842+
const resolvedFileUris = await Promise.all(fileUris.map(rawFileUri => {
838843
const fileUri = this.cliArgToUri(rawFileUri);
839-
if (fileUri) {
840-
const path = await this.resolveOpenable(hasWorkspaceFileExtension(rawFileUri) ? { workspaceUri: fileUri } : { fileUri }, pathResolveOptions);
841-
if (path) {
842-
pathsToOpen.push(path);
843-
}
844+
if (!fileUri) {
845+
return undefined;
844846
}
845-
}
847+
848+
return this.resolveOpenable(hasWorkspaceFileExtension(rawFileUri) ? { workspaceUri: fileUri } : { fileUri }, pathResolveOptions);
849+
}));
850+
851+
pathsToOpen.push(...coalesce(resolvedFileUris));
846852
}
847853

848854
// folder or file paths
849-
const cliPaths = cli._;
850-
for (const cliPath of cliPaths) {
851-
const path = pathResolveOptions.remoteAuthority ? this.doResolvePathRemote(cliPath, pathResolveOptions) : await this.doResolveFilePath(cliPath, pathResolveOptions);
852-
if (path) {
853-
pathsToOpen.push(path);
854-
}
855-
}
855+
const resolvedCliPaths = await Promise.all(cli._.map(cliPath => {
856+
return pathResolveOptions.remoteAuthority ? this.doResolveRemotePath(cliPath, pathResolveOptions) : this.doResolveFilePath(cliPath, pathResolveOptions);
857+
}));
858+
859+
pathsToOpen.push(...coalesce(resolvedCliPaths));
856860

857861
return pathsToOpen;
858862
}
@@ -900,32 +904,33 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
900904
lastSessionWindows.push(this.windowsStateHandler.state.lastActiveWindow);
901905
}
902906

903-
const pathsToOpen: IPathToOpen[] = [];
904-
for (const lastSessionWindow of lastSessionWindows) {
907+
const pathsToOpen = await Promise.all(lastSessionWindows.map(async lastSessionWindow => {
905908

906909
// Workspaces
907910
if (lastSessionWindow.workspace) {
908911
const pathToOpen = await this.resolveOpenable({ workspaceUri: lastSessionWindow.workspace.configPath }, { remoteAuthority: lastSessionWindow.remoteAuthority, rejectTransientWorkspaces: true /* https://github.com/microsoft/vscode/issues/119695 */ });
909912
if (isWorkspacePathToOpen(pathToOpen)) {
910-
pathsToOpen.push(pathToOpen);
913+
return pathToOpen;
911914
}
912915
}
913916

914917
// Folders
915918
else if (lastSessionWindow.folderUri) {
916919
const pathToOpen = await this.resolveOpenable({ folderUri: lastSessionWindow.folderUri }, { remoteAuthority: lastSessionWindow.remoteAuthority });
917920
if (isSingleFolderWorkspacePathToOpen(pathToOpen)) {
918-
pathsToOpen.push(pathToOpen);
921+
return pathToOpen;
919922
}
920923
}
921924

922925
// Empty window, potentially editors open to be restored
923926
else if (restoreWindowsSetting !== 'folders' && lastSessionWindow.backupPath) {
924-
pathsToOpen.push({ backupPath: lastSessionWindow.backupPath, remoteAuthority: lastSessionWindow.remoteAuthority });
927+
return { backupPath: lastSessionWindow.backupPath, remoteAuthority: lastSessionWindow.remoteAuthority };
925928
}
926-
}
927929

928-
return pathsToOpen;
930+
return undefined;
931+
}));
932+
933+
return coalesce(pathsToOpen);
929934
}
930935
}
931936
}
@@ -1097,7 +1102,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
10971102
return undefined;
10981103
}
10991104

1100-
private doResolvePathRemote(path: string, options: IPathResolveOptions): IPathToOpen<ITextEditorOptions> | undefined {
1105+
private doResolveRemotePath(path: string, options: IPathResolveOptions): IPathToOpen<ITextEditorOptions> | undefined {
11011106
const first = path.charCodeAt(0);
11021107
const remoteAuthority = options.remoteAuthority;
11031108

0 commit comments

Comments
 (0)