Why Fine-Grained Locking Was Rejected
In Python's early days, fine-grained locking (locking individual objects) was considered as an alternative to the GIL. However, it was rejected due to concerns about significantly increased complexity and potential performance overhead for single-threaded programs, leading to the adoption of the simpler, more pragmatic GIL, which offered better single-threaded performance.
The top 3
- Single-Threaded Performance Halved: Fine-grained locking approaches, when benchmarked, showed single-threaded Python code running up to 2x slower due to the significant overhead of acquiring and releasing locks for every object operation.
- C Extension Compatibility Nightmare: The existing vast ecosystem of C extensions for Python relies heavily on the GIL's guarantee of exclusive access; fine-grained locking would require a 'generational project' to rewrite or re-evaluate thread safety for these extensions, posing massive compatibility challenges.
- Increased Interpreter Complexity & Deadlocks: Adopting fine-grained locking would significantly increase the complexity of the Python interpreter, making it harder to develop and maintain, and could introduce new deadlock scenarios not present under the GIL.
Sources
Open the full topic