Skip to content

Commit d24ef48

Browse files
committed
Parallelize package init and test discovery operations
Some package initialization and test discovery operations could be parallelized to gain some modest speedups at no cost.
1 parent fbeb8b9 commit d24ef48

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/SwiftPackage.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,20 @@ export class SwiftPackage {
258258
): Promise<SwiftPackageState> {
259259
try {
260260
// Use swift package describe to describe the package targets, products, and platforms
261-
const describe = await execSwift(["package", "describe", "--type", "json"], toolchain, {
262-
cwd: folder.fsPath,
263-
});
264-
const packageState = JSON.parse(
265-
SwiftPackage.trimStdout(describe.stdout)
266-
) as PackageContents;
267-
268261
// Use swift package show-dependencies to get the dependencies in a tree format
269-
const dependencies = await execSwift(
270-
["package", "show-dependencies", "--format", "json"],
271-
toolchain,
272-
{
262+
const [describe, dependencies] = await Promise.all([
263+
execSwift(["package", "describe", "--type", "json"], toolchain, {
273264
cwd: folder.fsPath,
274-
}
275-
);
265+
}),
266+
execSwift(["package", "show-dependencies", "--format", "json"], toolchain, {
267+
cwd: folder.fsPath,
268+
}),
269+
]);
276270

277-
packageState.dependencies = JSON.parse(
278-
SwiftPackage.trimStdout(dependencies.stdout)
279-
).dependencies;
271+
const packageState = {
272+
...(JSON.parse(SwiftPackage.trimStdout(describe.stdout)) as PackageContents),
273+
dependencies: JSON.parse(SwiftPackage.trimStdout(dependencies.stdout)).dependencies,
274+
};
280275

281276
return packageState;
282277
} catch (error) {

src/TestExplorer/LSPTestDiscovery.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,17 @@ export class LSPTestDiscovery {
8585
swiftPackage: SwiftPackage,
8686
input: LSPTestItem[]
8787
): Promise<TestDiscovery.TestClass[]> {
88-
let result: TestDiscovery.TestClass[] = [];
89-
for (const item of input) {
90-
const location = client.protocol2CodeConverter.asLocation(item.location);
91-
result = [
92-
...result,
93-
{
88+
return Promise.all(
89+
input.map(async item => {
90+
const location = client.protocol2CodeConverter.asLocation(item.location);
91+
return {
9492
...item,
9593
id: await this.transformId(item, location, swiftPackage),
9694
children: await this.transformToTestClass(client, swiftPackage, item.children),
9795
location,
98-
},
99-
];
100-
}
101-
return result;
96+
};
97+
})
98+
);
10299
}
103100

104101
/**

0 commit comments

Comments
 (0)