Introducing Immortal Objects for Python
Instagram's pre-fork Django servers were losing shared memory to copy-on-write because CPython mutates reference counts and GC headers even on effectively read-only objects. PEP-683 Immortal Objects marks a special refcount value so the runtime never modifies an object's refcount or GC header, which keeps those pages shared and lets objects be shared across threads without the GIL. Upstreaming required preserving backward compatibility across platforms, compilers, word sizes and endianness, and careful register allocation held the refcount-path check to about a 2% regression. The change is a building block for PEP-684 (per-interpreter GIL) and PEP-703 (optional GIL).
Related posts
- Meta contributes new features to Python 3.12
Meta Engineering mediumAdeptMeta upstreamed several features into CPython 3.12, many derived from its Cinder runtime: immortal objects (PEP 683) that skip reference counting to cut copy-on-write memory in forked Instagram workers, the @typing.override decorator (PEP 698), and inlined comprehensions (PEP 709) running up to 2x faster. Other changes include opt-in eager asyncio tasks that resolve immediately-available results without event-loop scheduling, a LOAD_SUPER_ATTR opcode that avoids allocating super objects, and new async_tree and comprehension benchmarks in pyperformance. New runtime hooks, including vectorcall entrypoints, dict/type/function/code watchers, and a thread-safe perf-map API, let third-party JITs like CinderX plug into CPython.
- Using OxCaml to implement type-safe reference counting between OCaml and Python
Jane Street Tech Blog hardMasterWrapping Python objects as OCaml values in PyOCaml ties each object's release to the OCaml GC finalizer, so large data frames or GPU buffers can stay alive long after Python code drops them. OxCaml's modes fix this: `@ local` arguments let C glue borrow Python references without an incref, `@ unique` returns let it steal the reference back without one, and `borrow_` keeps a value unique across local calls. For manual control, `Py.newref`, a uniqueness-consuming `Py.decref` and `ppx_release` provide type-safe explicit reference counting that frees objects promptly even when exceptions are raised.
- Why we rewrote WAL-G for Postgres backups in Rust: Meet WAL-RUS
ClickHouse mediumAdept
WAL-RUS is an open-source Rust rewrite of WAL-G's Postgres backup and WAL archival tooling, built because Go's garbage-collected runtime made virtual memory hard to predict in resource-constrained managed Postgres environments where overcommit is disabled. It uses bounded worker pools, a persistent daemon with long-lived object storage connections, and a low-copy streaming read-compress-upload pipeline, while keeping WAL-G's WALG_ config variables and two-way archive compatibility. In a WAL-heavy benchmark with four workers archiving to S3, WAL-RUS peaked below 1 GB of virtual memory versus nearly 2.8 GB for WAL-G (over 70% less), with comparable throughput and CPU. pgBackRest also had tight memory but built a larger backlog under heavy WAL activity. WAL-RUS adds incremental backups based on Postgres 17 WAL summaries and is slated to become the default for ClickHouse Cloud's managed Postgres.
- chDB - A Rocket Engine on a Bicycle
ClickHouse hardMaster
chDB embeds the ClickHouse engine as an in-process Python module instead of shelling out to the 500MB clickhouse-local binary, using WriteBufferFromVector, Python memoryview and Pybind11 for zero-copy result retrieval. Getting jemalloc to work inside the shared library meant redirecting malloc with the linker flag -Wl,-wrap,malloc. That exposed crashes when glibc functions like getcwd returned glibc-malloc'd memory that was then freed by je_free, so the author patched jemalloc (PR #2424) to make arenas.lookup safe for checking ownership. The result cut memory usage by 50%, and chDB ranks as the fastest stateless/serverless engine on ClickBench. Later releases added SQL over Pandas DataFrames, query stats and Python UDFs.
- Understanding Garbage Collection in JavaScriptCore From Scratch
WebKit hardMasterJavaScriptCore's garbage collector is non-compacting, generational and mostly concurrent, with heavy use of lock-free programming. The explanation starts from a naive stop-the-world generational collector and adds pieces one at a time until it reaches JSC's real design. Along the way it covers BlockDirectory-based allocators (CompleteSubspace, PreciseAllocation, IsoSubspace), why per-object metadata is split between an inlined cellState and outlined isNew/isMarked bitvectors, and how write barriers and remembered sets keep marking correct. For incremental and concurrent collection it adds remembered-set scheduling and Space-Time Scheduler mitigations, which address up to 5x memory blowup.