4 ms·
You could fast path it by checking if the reference count of the list is `1` and avoid taking the lock in that case, I think.
by insanitybit 3y ago
You could fast path it by checking if the reference count of the list is `1` and avoid taking the lock in that case, I think.
- deleted 3y ago[deleted]
- blibble 3y agothat would work on x86 but not on an arch that can re-order loads (e.g. arm)
- insanitybit 3y agoI'm assuming it would be a fenced operation
- blibble 3y agobut then there's still an advantage to using the fenceless version :) (admittedly it's python so it's so slow it's probably not even measurable)
- insanitybit 3y agoYeah, for Python I feel like the difference between fenced vs unfenced doesn't matter. The primary cost is around your L3 cache getting slammed with contentious atomics but your L3 is already absolutely fucked if you're using Python.
- smaddox 3y agoCould you? What enforces only a single thread having access to a given reference? What about global variables?
- insanitybit 3y agoIf there's a refcount of 1 you can mutate the value safely because no other thread could be trying to read/ write to it. And the only thread that can give it to others would be the one that's doing that mutation, so it can't suddenly change. I'd assume that importing any sort of module level variable would imply an increment of the counter, but unsure.