feat(minor): Use Swift 6's isolated(any) feature to unblock the main actor and run benchmarks in whatever isolation context they require (#358)#359
Open
wadetregaskis wants to merge 1 commit into
Conversation
…un benchmarks in whatever isolation context they require (ordo-one#358).
supersonicbyte
approved these changes
Jun 3, 2026
isolated(any) feature to unblock the main actor and run benchmarks in whatever isolation context they require (#358)isolated(any) feature to unblock the main actor and run benchmarks in whatever isolation context they require (#358)
Contributor
|
Awesome, thanks for the contribution! Just a few concerns:
let closure = { @MainActor in
print("hello")
}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
See #358 for full details, but in short: previously, the main thread / actor was being blocked by a wait on a semaphore inside
runAsync, which meant any benchmark which relied on executing something on the main thread / actor / queue would deadlock.Now, the main actor / thread / queue is not blocked - and furthermore, benchmarks can annotate themselves with a global actor (e.g.
@MainActor) and be run there directly, by the Benchmark framework.How Has This Been Tested?
I added three new unit tests covering two critical cases:
@MainActorbenchmark runs on the main actor.(hopefully the explicit-hop case is made uncommon by being able to just
@MainActorthe benchmark to begin with, but the big concern is the indirect use of code which does that, such as in some library or deep down a callchain)Note: I've only tested this with Swift 6.2.4 on Sequoia.
Minimal checklist:
I have addedDocCcode-level documentation for any public interfaces exported by the package