Skip to content

Commit dca7546

Browse files
authored
Add swift.recordTestDuration setting (#1745)
* Add `swift.recordTestDuration` setting When running a large test suite full of tests that complete very quickly, VS Code spends a lot of time updating the test explorer UI. For every test the tree is refreshed, and in a suite where thousands of tests complete very quickly this can make the UI unresponsive and increase the amount of time the test run takes. The UI updates because the duration of the test item is different between runs, requiring the UI to change. As in the case described above, omitting the duration when passing or failing test items significantly improves performance. Introduce the `swift.recordTestDuration` setting which, when set to false, will omit the duration when recording test results. The default is `true`, making this optimization opt-in.
1 parent 6955cbe commit dca7546

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added Swiftly toolchain management support `.swift-version` files, and integration with the toolchain selection UI ([#1717](https://github.com/swiftlang/vscode-swift/pull/1717)
88
- Added code lenses to run suites/tests, configurable with the `swift.showTestCodeLenses` setting ([#1698](https://github.com/swiftlang/vscode-swift/pull/1698))
99
- New `swift.excludePathsFromActivation` setting to ignore specified sub-folders from being activated as projects ([#1693](https://github.com/swiftlang/vscode-swift/pull/1693))
10+
- New `swift.recordTestDuration` setting to disable capturing test durations, which can improve performance of heavy test runs ([#1745](https://github.com/swiftlang/vscode-swift/pull/1745))
1011
- Add a `Generate SourceKit-LSP Configuration` command that creates the configuration file with versioned schema pre-populated ([#1726](https://github.com/swiftlang/vscode-swift/pull/1716))
1112

1213
### Fixed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@
615615
"coverage"
616616
]
617617
}
618+
},
619+
"swift.recordTestDuration": {
620+
"type": "boolean",
621+
"default": true,
622+
"markdownDescription": "Controls whether or not to record the duration of tests in the Test Explorer. This is used to show the duration of tests in the Test Explorer view. If you're experiencing performance issues when running a large number of tests that complete quickly, disabling this setting can make the UI more responsive.",
623+
"scope": "machine-overridable"
618624
}
619625
}
620626
},

src/TestExplorer/TestRunner.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class TestRunProxy {
116116
private controller: vscode.TestController,
117117
private args: TestRunArguments,
118118
private folderContext: FolderContext,
119+
private recordDuration: boolean,
119120
testProfileCancellationToken: vscode.CancellationToken
120121
) {
121122
this._testItems = args.testItems;
@@ -275,7 +276,7 @@ export class TestRunProxy {
275276
this.clearEnqueuedTest(test);
276277
this.runState.passed.push(test);
277278
this.clearPendingTest(test);
278-
this.testRun?.passed(test, duration);
279+
this.testRun?.passed(test, this.recordDuration ? duration : undefined);
279280
}
280281

281282
public failed(
@@ -286,7 +287,7 @@ export class TestRunProxy {
286287
this.clearEnqueuedTest(test);
287288
this.runState.failed.push({ test, message });
288289
this.clearPendingTest(test);
289-
this.testRun?.failed(test, message, duration);
290+
this.testRun?.failed(test, message, this.recordDuration ? duration : undefined);
290291
}
291292

292293
public errored(
@@ -297,7 +298,7 @@ export class TestRunProxy {
297298
this.clearEnqueuedTest(test);
298299
this.runState.errored.push(test);
299300
this.clearPendingTest(test);
300-
this.testRun?.errored(test, message, duration);
301+
this.testRun?.errored(test, message, this.recordDuration ? duration : undefined);
301302
}
302303

303304
public async end() {
@@ -444,7 +445,14 @@ export class TestRunner {
444445
this.ensureRequestIncludesTests(this.request),
445446
isDebugging(testKind)
446447
);
447-
this.testRun = new TestRunProxy(request, controller, this.testArgs, folderContext, token);
448+
this.testRun = new TestRunProxy(
449+
request,
450+
controller,
451+
this.testArgs,
452+
folderContext,
453+
configuration.recordTestDuration,
454+
token
455+
);
448456
this.xcTestOutputParser =
449457
testKind === TestKind.parallel
450458
? new ParallelXCTestOutputParser(

src/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ const configuration = {
297297
.getConfiguration("swift")
298298
.get<boolean | ValidCodeLens[]>("showTestCodeLenses", true);
299299
},
300+
/** Whether to record the duration of tests in the Test Explorer. */
301+
get recordTestDuration(): boolean {
302+
return vscode.workspace.getConfiguration("swift").get<boolean>("recordTestDuration", true);
303+
},
300304
/** Files and directories to exclude from the Package Dependencies view. */
301305
get excludePathsFromPackageDependencies(): string[] {
302306
return vscode.workspace

0 commit comments

Comments
 (0)