u/SatadeepDasgupta

Windows doesn't have fork(), so I faked copy-on-write with VirtualProtect + exception handling to snapshot an in-memory KV store
▲ 0 r/cpp

Windows doesn't have fork(), so I faked copy-on-write with VirtualProtect + exception handling to snapshot an in-memory KV store

Was messing around trying to figure out how Redis does BGSAVE without blocking, and it comes down to fork() + COW on Linux — the OS shares pages between parent/child and only copies a page when someone writes to it. Windows has no fork(), so there's no free lunch here.

Ended up building a small toy project (Veyr) to see if I could fake the same behavior in user space on Windows. Wrote it up here if anyone's interested: https://satadeepdasgupta.medium.com/the-windows-machine-doesnt-have-fork-so-we-built-one-b10e1357aa4f

Short version of how it works:

• put the whole dataset in one big VirtualAlloc'd arena

• when snapshotting starts, VirtualProtect the arena to PAGE_READONLY

• any write thread that touches it now takes a hardware access violation

• catch that in a Vectored Exception Handler, copy the 4KB page to a shadow buffer before it changes, flip that page back to RW, resume execution

• background thread walks the arena and writes shadow pages for anything that got touched, live pages for anything that didn't

The first version I tried leaked memory into deadlocks because my handler was calling malloc for the shadow page allocation, and if the frozen thread happened to be holding the heap lock when it faulted, it just... never came back. Fixed by only calling VirtualAlloc directly inside the handler, never touching the normal allocator. Kind of an obvious fix in hindsight but took me a minute to figure out why it was randomly hanging.

Also built a lock-free hash map for it (atomic pointer swap per slot, immutable entries so there's no torn reads) since the snapshotting trick doesn't matter much if the map itself is the bottleneck.

Ran redis-benchmark against it and against Memurai (Redis-compatible Windows server) on the same box, same command. Veyr came out ahead by a decent margin but it's only doing GET/SET, no persistence format, no ACLs, none of the actual feature surface Memurai has, so take that as "minimal special-purpose thing beats general-purpose thing" rather than any real claim about which engine is better. Numbers are in the post if curious, didn't want to just paste a screenshot and let it become the whole conversation.

Known gap I haven't fixed: the map doesn't free old entries on overwrite, it just orphans them in a bump arena. Works fine for a benchmark, would leak forever under real sustained traffic. Need to add epoch-based reclamation or hazard pointers or something before this is anything other than a toy.

Source's up if anyone wants to poke holes in it: github.com/satadeep3927/veyr

Happy to be told I reinvented something that already exists, wouldn't be the first time.

u/SatadeepDasgupta — 2 days ago
▲ 53 r/tauri

Built a 5 MB Multi-Window IDE with Tauri v2 in 7 Days

​

About 7 days and 10 hours ago, I started playing around with an idea: building my own code editor.

I wasn't trying to build a product or compete with VS Code. I've always wanted to understand how editors work under the hood, so I opened a blank Rust project and started coding.

The result is Rune 1.0.0, a desktop IDE built with Rust + Tauri v2 + SolidJS.

A few things I implemented:

- True multi-window workspace management

- CLI integration ("rune <project>" and "rune <file>")

- Automatic routing of files to existing workspace windows

- Fast Rust-powered workspace indexing

- Persistent workspace and tab restoration

- PTY-backed integrated terminal

- Plugin architecture with Android Manifest-inspired permissions

One thing I'm particularly happy with is the multi-window behavior.

If I run:

rune my-project

Rune checks whether that workspace is already open. If it is, the existing window is focused. If not, a new workspace window is created.

Similarly:

rune src/main.rs

routes the file to the correct workspace window instead of spawning another instance.

The plugin system is also a little different from what I've seen in many editors. Plugins declare capabilities they require up front (similar to Android manifests), and Rune exposes only those approved APIs through a runtime "Rune" object.

The final Windows executable is around 5 MB, which still amazes me considering how much functionality is packed into it.

I have to say, Tauri v2 made a lot of this surprisingly pleasant to implement. Window management, IPC, filesystem access, shell integration, PTYs, and packaging felt much cleaner than I expected.

I'm curious:

- What's the most complex multi-window architecture you've built with Tauri?

- How are people handling plugin sandboxing and permissions?

- Has anyone built a plugin marketplace on top of Tauri applications?

Would love feedback from other Tauri developers.

GitHub: https://github.com/satadeep3927/rune/releases/tag/v1.2.0

u/SatadeepDasgupta — 1 month ago