Closed hassila closed 1 month ago
I have added a simple and self-contained package, while not displaying the same dramatic difference, still is slower by a factor 2.
jhansbo@niemann ~/S/MyTests> swift test --filter testInverseNormalUnivariateCDFLoop Fetching https://github.com/apple/swift-numerics from cache Fetched https://github.com/apple/swift-numerics from cache (0.38s) Computing version for https://github.com/apple/swift-numerics Computed https://github.com/apple/swift-numerics at 1.0.2 (0.03s) Creating working copy for https://github.com/apple/swift-numerics Working copy of https://github.com/apple/swift-numerics resolved at 1.0.2 Building for debugging... [35/35] Linking NormalDistributionPackageTests Build complete! (10.98s) Test Suite 'Selected tests' started at 2024-09-18 16:33:04.048. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-09-18 16:33:04.049. Test Suite 'NormalDistributionTests' started at 2024-09-18 16:33:04.049. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' started. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' passed (1.522 seconds). Test Suite 'NormalDistributionTests' passed at 2024-09-18 16:33:05.571. Executed 1 test, with 0 failures (0 unexpected) in 1.522 (1.522) seconds Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-09-18 16:33:05.571. Executed 1 test, with 0 failures (0 unexpected) in 1.522 (1.522) seconds Test Suite 'Selected tests' passed at 2024-09-18 16:33:05.571. Executed 1 test, with 0 failures (0 unexpected) in 1.522 (1.523) seconds Test run started. Testing Library Version: 94 (arm64e-apple-macos13.0) Test run with 0 tests passed after 0.001 seconds. jhansbo@niemann ~/S/MyTests> swift test --filter inverseNormalUnivariateCDFLoop Building for debugging... [1/1] Write swift-version--58304C5D6DBC2206.txt Build complete! (0.16s) Test Suite 'Selected tests' started at 2024-09-18 16:33:21.317. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-09-18 16:33:21.318. Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-09-18 16:33:21.318. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds Test Suite 'Selected tests' passed at 2024-09-18 16:33:21.318. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds Test run started. Testing Library Version: 94 (arm64e-apple-macos13.0) Test inverseNormalUnivariateCDFLoop() started. Test inverseNormalUnivariateCDFLoop() passed after 3.046 seconds. Test run with 1 test passed after 3.046 seconds.
jhansbo@niemann ~/S/MyTests> swift --version swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx14.0
MyTests.zip Adding a modified package for which you can run the tests in Xcode as well.
I would bet a peanut this is fixed by #659.
@hassila Are you able to capture a spindump
or sample
while the test runs slowly? If so, could you share it with us? (@jhansbo you too while you're here.)
@grynspan i did, it is attached in the original description in the middle... :-)
Here it is again @grynspan
https://github.com/user-attachments/files/17043776/Sample.txt
Oops, missed it. Thanks!
+ ! : 1164 __checkValue(_:expression:expressionWithCapturedRuntimeValues:mismatchedErrorDescription:difference:mismatchedExitConditionDescription:comments:isRequired:sourceLocation:) (in Testing) + 2316 [0x103e5a90c]
+ ! : | 1142 specialized static Event.post(_:for:testCase:instant:configuration:) (in Testing) + 424 [0x103e50880]
+ ! : | + 1132 Test.id.getter (in Testing) + 320 [0x103efd134]
+ ! : | + ! 554 TypeInfo.fullyQualifiedNameComponents.getter (in Testing) + 608 [0x103e836ec]
Yup!
Duplicate of #659
Is it possible to verify this with Xcode Beta 2, 16B5014f?!
Xcode 16.1 Beta 2 does not include the fix, however it's expected to be available in an upcoming Xcode beta.
Looks much better in Xcode 16.1 Beta 3! Thanks for that!
jhansbo@niemann ~/D/MyTests [1]> swift test --filter testInverseNormalUnivariateCDFLoop Building for debugging... [9/9] Linking NormalDistributionPackageTests Build complete! (8.86s) Test Suite 'Selected tests' started at 2024-10-11 11:53:00.675. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-10-11 11:53:00.676. Test Suite 'NormalDistributionTests' started at 2024-10-11 11:53:00.676. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' started. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' passed (1.462 seconds). Test Suite 'NormalDistributionTests' passed at 2024-10-11 11:53:02.139. Executed 1 test, with 0 failures (0 unexpected) in 1.462 (1.462) seconds Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-10-11 11:53:02.139. Executed 1 test, with 0 failures (0 unexpected) in 1.462 (1.462) seconds Test Suite 'Selected tests' passed at 2024-10-11 11:53:02.139. Executed 1 test, with 0 failures (0 unexpected) in 1.462 (1.463) seconds Test run started. Testing Library Version: 102 (arm64e-apple-macos13.0) Test run with 0 tests passed after 0.001 seconds.
jhansbo@niemann ~/D/MyTests> swift test --filter inverseNormalUnivariateCDFLoop Building for debugging... [1/1] Write swift-version-15FB3B08D7648C17.txt Build complete! (0.14s) Test Suite 'Selected tests' started at 2024-10-11 11:55:45.135. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-10-11 11:55:45.136. Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-10-11 11:55:45.136. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds Test Suite 'Selected tests' passed at 2024-10-11 11:55:45.136. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds Test run started. Testing Library Version: 102 (arm64e-apple-macos13.0) Test inverseNormalUnivariateCDFLoop() started. Test inverseNormalUnivariateCDFLoop() passed after 1.666 seconds. Test run with 1 test passed after 1.666 seconds.
jhansbo@niemann ~/D/MyTests> swift test --filter inverseNormalUnivariateCDFLoop -c release Building for production... [17/17] Linking NormalDistributionPackageTests Build complete! (11.27s) Test Suite 'Selected tests' started at 2024-10-11 11:56:21.700. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-10-11 11:56:21.702. Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-10-11 11:56:21.702. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds Test Suite 'Selected tests' passed at 2024-10-11 11:56:21.702. Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds Test run started. Testing Library Version: 102 (arm64e-apple-macos13.0) Test inverseNormalUnivariateCDFLoop() started. Test inverseNormalUnivariateCDFLoop() passed after 0.602 seconds. Test run with 1 test passed after 0.603 seconds. jhansbo@niemann ~/D/MyTests> swift test --filter testInverseNormalUnivariateCDFLoop -c release Building for production... [1/1] Write swift-version-15FB3B08D7648C17.txt Build complete! (0.17s) Test Suite 'Selected tests' started at 2024-10-11 11:56:40.703. Test Suite 'NormalDistributionPackageTests.xctest' started at 2024-10-11 11:56:40.704. Test Suite 'NormalDistributionTests' started at 2024-10-11 11:56:40.704. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' started. Test Case '-[NormalDistributionTests.NormalDistributionTests testInverseNormalUnivariateCDFLoop]' passed (0.420 seconds). Test Suite 'NormalDistributionTests' passed at 2024-10-11 11:56:41.125. Executed 1 test, with 0 failures (0 unexpected) in 0.420 (0.420) seconds Test Suite 'NormalDistributionPackageTests.xctest' passed at 2024-10-11 11:56:41.125. Executed 1 test, with 0 failures (0 unexpected) in 0.420 (0.421) seconds Test Suite 'Selected tests' passed at 2024-10-11 11:56:41.125. Executed 1 test, with 0 failures (0 unexpected) in 0.420 (0.422) seconds Test run started. Testing Library Version: 102 (arm64e-apple-macos13.0) Test run with 0 tests passed after 0.001 seconds.
So while it's really a lot faster it's still slightly slower than XCTest. As far as I can see roughly 40% slower in MyTest for release and 20% for debug builds.
Description
We've recently ported one of our packages to the new testing infrastructure, and it has been overall smooth - we can see one significant performance regression on the actual runtime of the test and have narrowed it down to the use of #expect in two places - I will provide the test code and timing results and sample of the runtime here, but we can work on providing a reduced case if this does not give enough hints on what the underlying problem can be.
The timing measurements we see are:
Release mode (
swift test -c release
):XCTest:
New Testing:
Debug (
swift test
):XCTest:
New Testing:
New Testing (with commenting out two #expect in the loops in the sample code provided below):
So basically we see a 10x runtime difference in release mode with XCtest winning over the new test framework - and a factor 6 in debug mode. Commenting out the two #expects in the sample below (best guess based on the sample) gave a significant improvement from 164 ---> 98 seconds runtime.
Attaching sample:
Sample.txt
Here is the test code in question for the new testing framework (no changes in the test itself, just using the new framework):
Expected behavior
We expected approximately the same runtime with the new testing framework.
Actual behavior
We saw a 5-10x test runtime regression for certain tests.
Steps to reproduce
No response
swift-testing version/commit hash
Built in with 6.0 release toolchain with Xcode 16
Swift & OS version (output of
swift --version ; uname -a
)