3 ms·
The GIL is an issue when you want parallelism. It is not relevant when talking about single thread performance.
by andreasvc 10y ago
The GIL is an issue when you want parallelism. It is not relevant when talking about single thread performance.
- eveningcoffee 10y agoAs I understand it, it eliminates some optimization possibilities and adds overhead. I do not have time to check the Python code to see how it is actually implemented (hence my question) but based on my knowledge it would imply at least a CAS operation to check and take the lock, writing the register values into memory (cache) and applying a memory barrier. You can not keep the values in the registries (elimination of optimization possibilities) and you add considerable overhead by needing memory barriers and CAS operations. I am not claiming that Python does it like this, I am just assuming that it should do it like this to obtain the guaranties of GIL.
- smegel 10y agoThe GIL is a condition variable and a mutex. Nothing fancy. In a single threaded program, it gets acquired once, if at all.
- eveningcoffee 10y agoMutex and a shared condition variable are expensive compared to the single instruction. But I had an impression that it is acquired before every atomic Python instruction and it looks that it is actually acquired for group of predefined number of instructions (100) that then are executed inside one GIL time frame [0]. Therefore it actually should not be a big obstacle to make Python code run fast by a JIT compiler. [0] http://www.dabeaz.com/python/GIL.pdf http://www.dabeaz.com/python/GIL.pdf