Repository navigation
5.8.0
Performance
-
Building and rendering
h.*trees scales acrossSTARIO_THREADSon
free-threaded Python. Each element holds a reference to itsTag, and
render increfed the tag's strings, so every thread wrote the refcounts of
the sameh.Td/h.Trobjects, and an HTML page served fewer requests
on 2 threads than on 1. On a free-threaded build aTagand its empty
element are now immortal (Py_INCREF / Py_DECREF only read them), and so
are its strings (interned), theclasses()/ attribute-name /data()
caches and their entries,@bakedstatic text, and the result of a
@bakedfunction without parameters. Render no longer takes references
on the tree it walks. Measured on 3.14t against 5.7.0:- Building and rendering a 50-row table on per-thread data, on 2 CPUs:
1.9-2.2x the throughput of one thread (was 0.3-0.45x); with
classes()and attributes, 2.0x (was 0.6x). - A 50-row page with classes and attributes on 4 CPUs: 3.8x at 4 threads
(was 0.36x). - Over HTTP, that page does 16.5k requests/s on 2 threads against 8.7k
on 1 (was 5.7k on 2, 8.1k on 1).
Builds with the GIL behave as before. Their single-thread timings are
unchanged within noise, and render is about 7% faster on a small tree. - Building and rendering a 50-row table on per-thread data, on 2 CPUs:
-
styles()checks for:;{}\with string literals instead of a
module-level regex (which free-threaded CPython increfs on every load).
About 7% faster with the GIL.
Changed
- On a free-threaded build a
Tagand a@bakedtemplate are never
freed. Create them once, at import (Widget = Tag("my-widget")), not per
request. Cache entries stay bounded by the caches' caps. A Python
subclass ofTagstays mortal (it works, but does not scale as well), and
a 32-bit build makes nothing immortal. - An
Element,SafeStringorAttrskept in a module-level variable and
put in every page is still increfed on each use, from every thread. For
static fragments that every request repeats, use a@bakedfunction
without parameters orclasses(): seedocs/free-threading.md.