willox / auxtools

Rust library for low-level interfacing with BYOND's virtual machine. Includes a remote debugger for the BYOND DreamMaker language.
MIT License
27 stars 32 forks source link

Replaces all the thread local dashmaps with static mut HashMaps #42

Closed Putnam3145 closed 9 months ago

Putnam3145 commented 3 years ago

DashMap is, internally, a Box<[RwLock<HashMap<K, V, S>>]>, with that internal slice having size num_threads4. This is highly useful and great... if you're accessing it from more than one thread. Instead, we're accessing it from a thread_local, and not just that, but a thread local which it is an actual impossibility to access from any thread other than the main Byond thread without invoking undefined behavior in the first place*.

To that end, I've made all the thread_locals thereof also raw static muts, which are quite a bit faster. This also replaces every thread local in the codebase which it is actually possible to replace, mind--there's one still left over, but there's no reason not to have that there.

I also replaced a few match chains with proper Option and-map-or function chains, cause I just sorta tend to do this when I see it.