Skip to content
Python
-
Python
Python GIL: Threads vs Processes vs asyncio, Measured
Threads, processes and asyncio timed on a Mac: CPU and I/O work with 1-8 workers, a counter race fixed with a Lock, and a blocked event loop measured.
-
Python
Python Profiling: What Actually Made Code Faster
timeit, cProfile and tracemalloc on a slow word counter: 4.39 s down to 31 ms step by step, and the folk optimizations that did nothing when measured.
-
Python
Python Iterators and Generators: Measured Memory
Hand-written __iter__/__next__, generators, yield from, itertools, the exhausted-iterator trap, and 390 MiB vs 0.3 KiB measured with tracemalloc.
-
Python
Python Functions: Scope, Default Args and Closures
Python functions from real runs: *args, **kwargs, / and *, the mutable default trap, LEGB and UnboundLocalError, late-binding lambdas, match, call cost.
-
Python
Python Decorators and Context Managers, Measured
Timing, retry and cache decorators, what breaks without functools.wraps, lru_cache on fib measured (x31,000), and context managers up to ExitStack.
-
Python
Python Types and Mutability: Names, Copies, is vs ==
Python basics from real runs: why 0.1+0.2 isn't 0.3, list aliasing and the [[0]*3]*3 trap, copy vs deepcopy, is vs ==, real tracebacks and measured costs.
↑