news.volyx.in

A viable solution for Python concurrency (lwn.net)

841 points by zorgmonkey · 1802 days ago · 358 comments on HN

Article summary

The article discusses a proposed solution for Python concurrency, which involves removing the Global Interpreter Lock (GIL) from the CPython interpreter. The GIL is a mechanism that prevents multiple threads from executing Python bytecodes at once, which can limit the performance of multi-threaded programs. The proposed solution uses a combination of biased reference counting, immortal objects, and deferred reference counting to achieve thread safety without the GIL. This approach has shown promising results, with a 10% improvement in single-threaded performance and significant speedups in multi-threaded programs.

Main themes

  • Python concurrency
  • GIL removal
  • thread safety
  • performance optimization
  • backward compatibility
  • alternative parallelization approaches
  • C extensions and compatibility
  • PyPy and garbage collection
  • language design and trade-offs

What commenters say

  • Removing the GIL will break existing programs that rely on its presence, and a significant amount of work will be needed to update these programs.
  • The performance benefits of removing the GIL outweigh the potential drawbacks, and it is a necessary step for Python to remain competitive.
  • Alternative approaches, such as using PyPy or other parallelization libraries, may be more effective and easier to implement than removing the GIL.
  • The proposed solution is not compatible with all existing C extensions, and additional work will be needed to ensure that these extensions can be used safely in a multi-threaded environment.
  • Guido's requirement that GIL removal not degrade single-threaded performance is no longer a blocker, as the proposed solution has achieved a net performance improvement.
  • The article's presentation of the proposed solution is overly optimistic, and the actual implementation will be more complex and difficult to achieve.
  • A global GIL switch would be impractical, and instead, the GIL could be disabled or enabled locally for specific parts of a program.
  • PyPy's use of a tracing garbage collector makes it difficult to apply the same recipe for parallelism as CPython.