I'm processing ~10k events between two different classes. One is fetching them, and the other is storing them in a dictionary. Now since the fetching class is also doing more stuff with the data than just passing it to the second class, it really doesn't make a lot of sense to send them over as a big bulk, but rather I'm processing them like
actor Fetcher {
let someProcessor = Processor()
func getData() async {
let results = await Rest.getData()
for result in results {
await someProcessor.doStuff(with: result)
await someOtherObject.handle(result)
}
}
}
actor Processor {
func doStuff(with result: Result) async {
// ...
}
}
now maybe you can see the problem. With both of them being actors, I keep sending around data between threads. Processing ~10k results thus takes 8 seconds. This is mostly because of thread switches. If I make my code non-thread-safe by removing the actor keyword it takes less than a second. It would remove some functionality of my code if I did that though. Is there a way to tell swift that these two actors should always run in the same Thread to avoid the switching?