You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Graph executor: hand each kernel its inputs without a second full copy #1679
The shared graph executor builds every kernel's context through _freeze_frame in packages/microcosm-graph/src/microcosm/graph/executor.py. It deep-copies each table the kernel reads (table.copy(deep=True)) and marks the copy read-only, while the executor also keeps the stored population. So every node holds a second full copy of its input tables before the kernel makes its own working copy. The UK, US and NZ graphs all build kernel contexts this way.
Why it matters now. In #1538 (#931) the UK spine carries 15 geographic clones of every household. One clone's final frame measures 0.39 GiB in memory, so at 15 clones one copy is about 6 GiB. Commit 658378b on #1538 removed two duplicate copies in the UK kernels. A spine stage now holds three copies at once: the stored population, this frozen copy and the kernel's own frame. This is the one copy left that only the executor makes. The 16 Nov review of #1538 found it.
What done looks like
The executor hands each kernel its inputs without a second full copy, and a kernel still cannot change the stored population.
Tests on invented frames: a kernel that writes a cell, assigns a column or writes through an array must fail or change only its own copy, and the stored population stays byte-identical. Cover NumPy-typed and extension-typed columns (string, category, nullable integer and boolean).
A tracemalloc measurement before and after (the held and peak copies beside the stored population), and a regression test that bounds the peak.
No value change: the graph parity fixtures' outputs stay the same, and any implementation hash that moves is re-pinned with tools/graph_parity_repin.py.
Related.#1666 (open, by anth-volk) adds copy-on-write sharing of unchanged tables to Frame (_adopt, replace_tables, with_columns) and a source check that refuses raw writes into shared buffers. The lock pins pandas 3.0.3, where copy-on-write is always on. This change should build on #1666. Its findings for follow-up work apply here too: np.<ufunc>.at ignores the read-only flag, and extension-typed columns can return writable arrays that share the column's memory.
Activity