January 6th, 2025

Musings on Tracing in PyPy

The blog post examines tracing Just-In-Time compilers, particularly in PyPy, noting their performance inconsistencies and challenges. It concludes that tracing is a pragmatic choice for handling Python's complexity.

Read original articleLink Icon
Musings on Tracing in PyPy

The blog post discusses the state of tracing Just-In-Time (JIT) compilers, particularly in the context of PyPy, a Python interpreter that employs a meta-JIT architecture. The author reflects on a Twitter discussion regarding the effectiveness of tracing JITs, noting that while they were once popular, their performance can be inconsistent. Tracing JITs compile code by following execution paths, particularly focusing on loops, which can lead to aggressive optimizations like partial inlining. However, they also face challenges such as performance cliffs and corner cases that complicate their implementation. The author contrasts PyPy's tracing approach with method-based JITs, highlighting that while tracing can yield significant performance benefits, it may not be the best choice for all contexts. The post concludes that for PyPy, tracing remains a pragmatic choice due to its ability to handle Python's complexity without altering the language itself. The author expresses optimism about the future of Python's performance, especially with the emergence of new JIT implementations.

- Tracing JITs focus on execution paths, particularly loops, for optimizations.

- PyPy uses a meta-JIT architecture, allowing it to support multiple Python versions.

- Tracing can lead to performance cliffs and corner cases that complicate its use.

- The author believes tracing is a pragmatic choice for PyPy given Python's complexity.

- Future developments in Python's performance are anticipated with new JIT implementations.

Link Icon 2 comments
By @kragen - 4 months
I feel like LuaJIT probably deserves a mention here. It doesn't always get astounding performance, but it very often does, and you get all the inlining and dynamic specialization goodness that tracing JITs make cheap. And it demonstrates extremely convincingly that PyPy's difficulty with invoking native code isn't essential to tracing JIT.
By @Qem - 4 months
Nice article. I'd like to also know PyPy developers thoughts on the copy-and-patch approach chosen to implement the new JIT under development for CPython.