Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Reduce overhead of .expectationChecked event handling in #expect(). #657

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 3, 2024

Explanation: Optimizes the implementation of #expect(), in particular the parts that ask for fully-qualified type names and generate .expectationChecked events.
Scope: 6.0 branch
Issue: N/A
Original PR: #610
Risk: Moderate—refactors code inside #expect() and introduces a new lock and atomic value used by them.
Testing: New unit test coverage, existing coverage.
Reviewer: @briancroom @suzannaratcliff

…`. (#610)

This PR refactors the implementation of `#expect()` and `#require()` a
bit such that they don't incur more than minimal overhead posting
`.expectationChecked` events if nobody is listening for them (which,
currently, nobody is.)

We considered removing `.expectationChecked` outright, but XCTest has
historically had a number of requests for a way to observe calls to
`XCTAssert()` etc. even when they pass, so we opted not to remove the
event kind at this time.

This PR also introduces a cache for fully-qualified type names so that
we don't need to call into the runtime to get them as often.

Overall speedup is approximately **90% or 11x**. Test time for a tight
loop of 1,000,000 `#expect()` calls goes from 5.898893 seconds down to
0.515558291 seconds (as measured on my work computer.)

Resolves rdar://133517028.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@grynspan
Copy link
Contributor Author

grynspan commented Sep 3, 2024

@swift-ci test

@grynspan grynspan merged commit 3e30663 into release/6.0 Sep 3, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/jgrynspan/133517028-minimize-expectationChecked-overhead-6.0 branch September 3, 2024 23:18
ahoppen added a commit to ahoppen/swift-testing that referenced this pull request Sep 4, 2024
ahoppen added a commit that referenced this pull request Sep 4, 2024
Revert "[6.0] Reduce overhead of `.expectationChecked` event handling in `#expect()`. (#657)"
grynspan added a commit that referenced this pull request Sep 4, 2024
…pect()`. (#657)

**Explanation:** Optimizes the implementation of `#expect()`, in
particular the parts that ask for fully-qualified type names and
generate `.expectationChecked` events.
**Scope:** 6.0 branch
**Issue:** N/A
**Original PR:** #610
**Risk:** Moderate—refactors code inside `#expect()` and introduces a
new lock and atomic value used by them.
**Testing:** New unit test coverage, existing coverage.
**Reviewer:** @briancroom @suzannaratcliff
@grynspan
Copy link
Contributor Author

grynspan commented Sep 4, 2024

See also #659

@grynspan grynspan added this to the Swift 6.0.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Performance issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants