Zig Electron Replacement

Watched Andrew’s video about data oriented design the other day and it got me thinking about what apps unnecessarily slow me down on a daily basis. The road always came back to electron. Since zig already has bun, would there be any interest in a z based drop in electron replacement. We can call it zelectron until a less shitty name is proposed.

3 Likes

How would you approach the ‘browser engine problem’?

You could use the operating system webview like Tauri, Cordova or GitHub - webview/webview: Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows). (formerly known as zserge/webview), that would allow small application bundles but at the cost that you’ll need to worry about non-Chromium browser engines.

…or the alternative would be integrating Chromium, but then that wouldn’t be much of an advantage over using Electron in the first place.

But in both cases you wouldn’t see any performance advantage over Electron, because in the end all code that needs to do any rendering needs to go through JS-APIs, you could at most delegate the ‘application logic’ into a FFI-DLL compiled from Zig code (but then you can already do that with Electron or Tauri).

Getting rid of the browser engine completely would mean that it’s more like a native cross-platform application framework like Qt or GTK, but then it wouldn’t need a V8^H^HJavaScriptCore wrapper like Bun, nor would it be anything like Electron.

2 Likes

Zig bindings for WebUI might be an adequate starting point, and may already exist.

I will say that native GUI bindings will always feel and function nicer than what WebView can provide, but there’s a place for them nonetheless. Zig’s native cross-compilation and WASM targeting are strengths here.

I would much rather deal with the quirks of Safari (let’s face it, it’s Chrome or it’s Safari at this point) than inflict an entire bundled web browser on users. It feels like an insult to the spirit of Zig to use it to ship a multi-gigabyte binary which loads into a minimum GB of memory.

Making pure-Zig cross-platform native GUI in the style of QT, well it’s a very different story. Promising, actually, but what I’m gesturing at is that your post (@floooh) explores three very different projects.

Two of which are quite promising, and one of those is immensely easier than the other, although even “what if Tauri but Zig” is only ‘easy’ by comparison with writing a modern QT equivalent from scratch.

Good idea though? Yes.

Electron is kinda a pain due to the separation between the renderer thread and the background thread. Something that works like NW.js where the two are unified would be a major improvement.

Have you taken a look at Orca? It’s not written in Zig, but it is a cross platform alternative that provides a lot of the benefits of electron with none of the browser jank.

@kristoff did an interview with the head developer on Zig Showtime. It’s a good watch.

1 Like