"Removing the `UnsafeCell..." <- > <@jannic:matrix.org> Removing the `UnsafeCell` might actually lead to slightly better code generation: https://godbolt.org/z/bo5KfsnWG > This is probably the only case where it matters. Mutex is only needed to make something Sync. Most types already are Sync - the two main exceptions are things containing any type of Cell, and things containing pointers. For things which already contain Cells, it doesn't matter if we wrap them in another UnsafeCell. But for pointers, it may: Even if the pointer itself is immutable, if it is wrapped in an UnsafeCell, the compiler can't know that. So if the pointer is dereferenced multiple times, the pointer itself needs to be reloaded multiple times as well. Without the UnsafeCell, the compiler, having a & to the Mutex, can be sure that the pointer won't change. > Therefore, `mutex1` (without UnsafeCell) is one instruction shorter than `mutex2` (with UnsafeCell). hmmmm it feels like this godbolt is a proof removing the UnsafeCell is unsouND?