This is an automated archive made by the Lemmit Bot.
The original was posted on /r/rust by /u/codedcosmos on 2025-05-07 06:25:01+00:00.
By RefCell really what I mean is any synchronization primitive. So for the sake of the question, Rc
, Arc
, Mutex
, RefCell
, RwLock
, etc are all unpermitted.
I’ve been writing my own ECS for fun, and ended up using Rc<RefCell>
(it’s just for fun so the performance impact is acceptable). I chose it because I couldn’t figure out a way to convince the borrow checker that what I was doing was valid (even if I knew it was, I never had more than one mut reference and never had mut references and references mixed).
That got me thinking, is it possible to write an ECS with just Rusts borrow checker validating everything. E.g. no synchronization primitives, no unsafe?
I honestly doubt it is, maybe if NLL Problem case 4 gets solved I could see it happening. But my understanding is that problem case 3 isn’t yet solved by polonius, let alone 4.
I wanted to ask regardless, there are a lot of smart crabs on this subreddit after all.
Edit/Update: I tried RefCell anyway, what could possibly go wrong. I decided to benchmark against legion for a very non-scentific test and it was a lot more performant that I expected.
- 100_000_000 iterations
- both single threaded, removed legions parallel feature
- Mine (RefCell) 4069ms
- Legion 5538ms
Note that this is just pure iteration speed with mutations in each iteration. Also this approach lacks some features that legion provides.