Swift-erlang-actor-system

todsacerdoti | 264 points

I'm involved with this project and wanted to provide some context. This is an extraction for a much larger effort where we're building a web browser that can render native UI. Think instead of:

`<div>Hello, world!!</div>`

we can do:

`<Text>Hello, world!</Text>`

I want to be clear: this is not a web renderer. We are not rendering HTML. We're rendering actual native UI. So the above in SwiftUI becomes:

`Text("Hello, world!")`

And yes we support modifiers via a stylesheet system, events, custom view registration, and really everything that you would normally be doing it all in Swift.

Where this library comes into play: the headless browser is being built in Elixir to run on device. We communicate with the SwiftUI renderer via disterl. We've built a virtual DOM where each node in the vDOM will have its own Erlang process. (I can get into process limit for DOMs if people want to) The Document will communicate the process directly to the corresponding SwiftUI view.

We've taken this a step further by actually compiling client-side JS libs to WASM and running them in our headless browser and bridging back to Elixir with WasmEx. If this works we'll be able to bring the development ergonomics of the Web to every native platform that has a composable UI framework. So think of actual native targets for Hotwire, LiveWire, etc...

We can currently build for nearly all SwiftUI targets: MacOS, iPhone, iPad, Apple Vision Pro, AppleTV. Watch is the odd duck out because it lacks on-device networking that we require for this library.

This originally started as the LiveView Native project but due to some difficulties collaborating with the upstream project we've decided to broaden our scope.

Swift's portability means we should be able to bring this to other languages as well.

We're nearing the point of integration where we can benchmark and validate this effort.

Happy to answer any questions!

bcardarella | 11 hours ago

I worked on this project, thanks for sharing it! This is part of a larger otp-interop GitHub org with projects for things like running BEAM on mobile devices, disterl over WebSockets, filtering messages sent over disterl, etc. Happy to answer any questions about the project.

carson-katri | 11 hours ago

so can iOS devices (say iPhones) join Erlang actor cluster now? can someone explain?

nikolayasdf123 | 19 minutes ago

This is neat. I'm not a swift user, but I did work on a project where we made heavy use of JInterface (which ships in OTP), which is effectively the same thing but for JVM languages. It worked great and allowed easy reuse of a bunch of Java libraries we already had. Pretty painless interop model, imo.

rozap | 10 hours ago

Very cool work.

DeepYogurt | 5 hours ago

One thing for which I can't get a clear answer: Swift uses automatic reference counting. It seems that it needs atomic operations that are expensive.

Does this allow somehow to sidestep this? Since the data is all thread-local, it should be possible to use non-atomic counters?

cyberax | 11 hours ago
[deleted]
| 5 hours ago