Part 17, the last of a series on the CPython runtime: CPython 3.6.5 to 3.9.1 built with one compiler and measured side by side. Method calls 24% cheaper since 3.6, range(10) 24% cheaper in 3.9 alone, and Part 13's …
Part 16 of a series on the CPython runtime: what a process copies when it forks, and what it shares when it doesn't. A lock held by a thread that doesn't exist in the child, os.register_at_fork as the fix, logging …
Part 15 of a series on the CPython runtime: what import does on Linux, counted in system calls. Python 2.7 making 18,469 of them for import json with 100 path entries and Python 3.8 4,372, a .pyc that keeps running old …
Part 14 of a series on the CPython runtime: one loop on CPython 3.8, PyPy 7.3, Cython and Numba, from 0.34 seconds to 5 milliseconds. PyPy's JIT trace read op by op, the guard that falls back to big integers, the bridge …
Part 13 of a series on the CPython runtime: one slow program, five ways of looking at it. cProfile blames str.split, py-spy blames a list comprehension, perf finds the cycle collector taking 60% of the time and no Python …
Part 12 of a series on the CPython runtime: the changes in Python 3.8 that aren't about the language, measured against 3.7.5 in one sitting. A LOAD_GLOBAL cache that made global reads four times cheaper in a function …
Part 11 of a series on the CPython runtime: the buffer protocol, the interface that lets Python objects and C code share one block of memory without copying it. One bytearray seen as a memoryview, a NumPy array and a C …
Part 10 of a series on the CPython runtime: a C extension module written by hand against Python 3.7.4's C API. Arguments parsed from a tuple and from 3.7's new METH_FASTCALL array, errors as NULL plus an exception, a …
Part 9 of a series on the CPython runtime: where Python numbers are C numbers and where they stop being. Addition at 15 ns up to 2^300 and 400 ns at a thousand digits, multiplication going from schoolbook to Karatsuba, …
Part 8 of a series on the CPython runtime: the dict in Python 3.7.3, read from memory. The compact index table and entries array, the probing recurrence reproduced in Python and checked against the real table, the size …
Part 7 of a series on the CPython runtime: how Python 3.7.2 stores a str. PEP 393's three widths, read from the string header, and one emoji that makes a megabyte of log text four megabytes; a UTF-8 copy that C …
Part 6 of a series on the CPython runtime: the Global Interpreter Lock as it has worked since Python 3.2, measured in 3.7.1 on four CPUs. Four threads counting no faster than one, the GIL changing hands every 5 ms as a …
Part 5 of a series on the CPython runtime: pymalloc, the allocator under every small object. Size classes, 4 KiB pools and 256 KiB arenas, a pool header read from Python, why 4,000 surviving floats keep 95 MiB of memory, …
Part 4 of a series on the CPython runtime: what ob_refcnt does over an object's life. Objects freed at the exact moment their count reaches zero, the references that keep them alive without anyone noticing, the cycle …
Part 3 of a series on the CPython runtime: why every Python-to-Python call nests one more C call to the interpreter loop, measured at 384 bytes of C stack each in Python 3.7.0. What the recursion limit really guards, how …
Part 2 of a series on the CPython runtime: how a Python function becomes 30 bytes of bytecode and how one C function runs them. The compile stages, wordcode decoded by hand, every push and pop of a running loop printed …
Part 1 of a series on the CPython runtime: what a Python value is in memory. The integer 1000, a float, a tuple and a list read byte by byte through id() on a stock Ubuntu 18.04, the same fields printed from C, and the …