I have been interested in DA since it was announced, and today I thought of a potential use-case that I'd like to run by the community to see if it makes sense or if there's a better (easier / cleaner) way of doing it.
Today we launched a project that uses Swift Wasm to build parts of our mobile app for use in our web app in order to share code and improve performance there. We were able to use 100% of our mobile app's business logic for the most essential part of our app: the song "Player", where you learn how to play songs on piano. The project was a lot of fun for our team, and a huge success for us goals-wise, so we'd like to continue to improve what we've made there.
What I'd like to do next is move our (Swift) audio processing code off the main thread and into a Web Worker / Audio Worklet. There are many ways we might do that "by hand", but it seems to me like it could be a great use-case for DA.
From what I understand we could instantiate another instance of our Wasm binary in a web worker and serialize calls (i.e. messages) to and from the worker via a DistributedActorSystem. I think we'd have to do this because a worker cannot share memory with the JS main thread. Since distributed actors – kind of by definition – don't share memory space with each other, and pass messages that are serialized and deserialized at a defined boundary, it seems like the abstraction would fit quite well.
For our use case it'd probably be enough to call methods on the distributed actor (worker) and have it "return" a single value for each call. i.e. for our use case there can be a 1:1 relationship between calls to the actor and calls back from it. So that should be easy enough to implement.
That said, it'd be interesting to know if there are standard ways for "child" workers to call back to the "parent" process with DA (for later / other, more general, use cases). Is this just a case of creating another DA on the "parent" and calling it directly from the child? Or are there other, better, ways?
Is there something I'm missing? Basically I'd write the Distributed Actor System as follows: it would run some JavaScript code (via the fantastic JavaScriptKit), which creates a Worker that instantiates another copy of the Wasm binary (effectively forking the Wasm process in another thread). The JavaScript code it runs in the worker would set up the message exchange and the Swift DA-System code written would deal with (de)serialization.
Am I crazy? Or is this a good use case for DA?
edit: my biggest concern after looking at the DA repo is that the feature itself appears quite heavyweight. We are looking to save binary size where we can and it appears DA has dependencies on Foundation, NIO, Atomics, and more – this may end up being a blocker for us