Skip to content

perf(comp): a shared type read only by peeks keeps its fields uncounted (frozen nodes) - #55

Merged
nicolas-abril merged 3 commits into
opt/integrationfrom
opt/repr-frozen
Dec 1, 2026
Merged

nicolas-abril merged 3 commits into
opt/integrationfrom
opt/repr-frozen

Conversation

@nicolas-abril

Copy link
Copy Markdown
Owner

A shared type's node keeps its box fields uncounted when nothing ever takes them: a representation chosen by how the program reads the type.

What. When a value of a type is shared, the type gets the ctr fact and every node of every constructor seals its box fields on build: a count cell per field, so that a shared read (ctr_take) can take the fields. A constructor is frozen when no match ever takes its node: no owned match of it anywhere, and no borrowed read of it in a unit that keeps a lent word (term_keep of a + root) or answers a borrowed part (FL.rets). A frozen constructor's builds store fields plain; when its value is shared only the root is counted; every read peeks it (term_peek), and the last drop frees the whole structure. Not for runtime-laid or foreign-named types; a node of words alone is left as it was (its seal is a no-op). The thaw facts join the c_units fixed point (a thaw is a fact only for a shared constructor with a box field, so no extra rounds).

Where it pays. Found by a survey of the 244 benchmarks with run-time node counters: interval-tree's chunk lists are built once and walked 406M times through borrowed reads, each step loading a count cell and then the node. The other three programs whose C changes are the delaunay ports.

program instructions cycles 10 threads
parallel-ml/interval-tree -17.8% -35.5% -30%
parallel-ml/delaunay -1.4% -0.9% (sweep median -1.1%) level
delaunay-animation (2 ports) level level level

All other 240 benchmarks emit byte-identical C. Emit time over the 244: level (median ratio 0.999).

Checks. Cluster test gate 1996/1996. New tests tests/run/frozen_{walk,match,keep,back}.bend (frozen lists and trees shared across forks; nested, two-scrutinee and catch-all borrowed matches; a lent read that becomes owned; a tree taken from a generic box by an owned match). All 9 tests whose C changes: same output as the interpreter, 0 live words with -DBEND_POISON at 1 and 8 threads. Wrong versions: no thaw on an owned match (fail-stop on frozen_keep and frozen_back), seal never (crash/fail-stop): caught. The keep and borrowed-answer thaws are defensive: with either removed, no benchmark's C changes (in the corpus an owned match always thaws first). GPU: the 17 bend-runtime programs at --gpu on (C unchanged for them).

comp.ts +381 ttok.

🤖 Generated with Claude Code

nicolas-abril and others added 3 commits December 1, 2026 14:18
…uncounted (frozen)

A type made shared (the ctr fact) seals every box field of every node on
build: a count cell per field, so that a shared read can take the node's
fields. A constructor whose nodes no match takes (no owned match of it
anywhere, no borrowed read of it in a unit that keeps a lent word or answers
a borrowed part) is frozen: its builds store fields plain, its root alone is
counted when shared, every read peeks it and the last drop frees it whole.
interval-tree's chunk lists (read 406M times through a count cell each) and
its query tree: -35% cycles, -30% at 10 threads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… field

A thaw that changes no build added a fact and so, at times, a c_units round
(emit time +4% median over the 244 benchmarks); now none (0.999), C the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nicolas-abril
nicolas-abril merged commit 04b726a into opt/integration Dec 1, 2026
1 check failed
nicolas-abril added a commit that referenced this pull request Dec 1, 2026
…33, #34, #36, #39, #44, #61-#68): record their heads

Each is a port onto main of integration's own branch, its content already
here (integration keeps the original commits; the ports add type fixes,
line wraps, moved pieces and #68's book_passes, applied in the previous
commit). Groups: #61 (#9 #11 #15 #32 #41 #42), #62 (#26 #56), #63 (#48 #50
and compile-time), #64 (#19 #20 #45), #67 (#55 #58), #68 (#54); par-defer
(#43) is now part of #34, lazy-startup's parts are in #16 and #34. This
merge records their heads (-s ours: no content change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant