stroughtonsmith,
@stroughtonsmith@mastodon.social avatar

Does Swift's MainActor annotation actually do anything at runtime to ensure code is called from the main thread, or is it entirely a compile-time sanity check that might not play well across opaque binary/framework boundaries?

grynspan,

@stroughtonsmith actor isolation is enforced at compile time. MainActor.assertIsolated() and .assumeIsolated() can be used for runtime verification.

stroughtonsmith,
@stroughtonsmith@mastodon.social avatar

@grynspan that's helpful, thanks!

dgregor79,
@dgregor79@sfba.social avatar

@stroughtonsmith There's a compiler flag -enable-actor-data-race-checks that enables additional runtime checking for actors in existing compilers. Swift 6 is getting an improved version that's documented at https://github.com/apple/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md

stroughtonsmith,
@stroughtonsmith@mastodon.social avatar

@dgregor79 I guess that emits some glue around actor usage? Is there much overhead?

dgregor79,
@dgregor79@sfba.social avatar

@stroughtonsmith it emits a check on entry to a synchronous, actor-isolated function that ensures it’s running on the right actor. The check itself is fairly cheap, but could add up in a. Tight loop. The Swift 6 implementation should have lower overhead, because it can limit checks to those places where it is interfacing with code that isn’t statically checked.

stroughtonsmith,
@stroughtonsmith@mastodon.social avatar

@dgregor79 very helpful to know, thanks!

paulgessinger,

@stroughtonsmith I believe it’s a global actor that uses a special executor that talks to Dispatch as per the original swift evolution proposal

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • GTA5RPClips
  • Durango
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • tacticalgear
  • JUstTest
  • osvaldo12
  • tester
  • cubers
  • cisconetworking
  • mdbf
  • ethstaker
  • modclub
  • Leos
  • anitta
  • normalnudes
  • megavids
  • provamag3
  • lostlight
  • All magazines