Blog
Every entry, newest first — the claim, the mechanism under it, and the number that settles it.
- Entries
- 13
cProfile Slowed It 2.9x and Moved the Ranking by One Point
cProfile adds a flat 25 to 30 ns to every call it observes. That inflates a 47 ns function's reported time by 1.57x and a one-microsecond function's by nothing at all.
UTF-8 by Default Fixes a Silent Bug and Adds a Loud One
Under a Latin-1 locale, CPython 3.13 reads a UTF-8 file as mojibake and raises nothing. 3.15 reads it correctly and raises on the Latin-1 file 3.13 read fine.
Swapping Two Imports Moved 5.5 ms to a Different Module
Importing logging before asyncio moves 5.5 ms from asyncio's line to logging's. The program does the same work. The cumulative column charges whoever got there first.
lazy import Moved 26.8 ms and Removed None of It
A lazy import of asyncio costs no measurable time and no modules at startup. Read the name once and 26.4 of the 26.8 ms come back. Deferral is not removal.
A NamedTuple Read Cost 0.81x a Plain One, Then 1.9x
On CPython 3.10 a NamedTuple attribute read cost 0.81x a read through an instance dictionary. On 3.11 it costs 1.90x. Nothing about NamedTuple changed.
getsizeof Reports 296 Bytes, Then 96, for the Same Class
sys.getsizeof reports 296 bytes for a class's first instance dict and 96 once twenty-six exist. The instance itself costs 96 bytes and getsizeof says 48.
Slots Did Not Get Slower, One Build Did
A read through __slots__ costs 24% more than one through an instance dictionary on CPython 3.13.2. Rebuild the same version and the gap goes away.
Type Hints at Run Time
Annotations cost nothing per call and everything at import. Reading __annotations__ takes 24 ns; resolving the same class with get_type_hints takes 3.4 µs, 140x more.
Where Your Django Request Time Actually Goes
Removing Django's entire default middleware chain saved 0.02 ms per request. Fixing one N+1 query on a fifty-row list view saved 3.30 ms.
The Real Cost of an async Call
Awaiting a coroutine that never suspends costs 53 ns against 24 ns for a plain call. Wrapping the same coroutine in a Task and awaiting it costs 28,958 ns.