Skip to content

perf(comp): compile time: Nat ranges proved once (nv_book), match literals and arm walks memoized, emission memos that drop dead terms - #63

Draft
nicolas-abril wants to merge 9 commits into
mainfrom
opt/compile-speed
Draft

nicolas-abril wants to merge 9 commits into
mainfrom
opt/compile-speed

Conversation

@nicolas-abril

Copy link
Copy Markdown
Owner

On main (6180be5b)

This PR is a port onto main, on main: 9 commits of its own, with no integration history (head 2909a635).
It replaces #48, #50.

Port notes

Checks

  • Cluster gate (every test, every lane): 1879 / 1879 pass.
  • Locally: no new tsc errors against main, no new comp.ts lines over 80, its tests pass on the C and JS lanes (plus 40 lane runs of existing tests; run/array_slab fails on main too).
  • comp.ts: +9129 tokens (ttok -m gpt-3.5-turbo) over main, which is at 65,989 of the 66,000 cap.

Performance was measured on integration when this change merged there (see the original description or the replaced PRs); it has not been re-measured on main.

What it does

The change of the PRs it replaces, ported together:

Their descriptions hold the design and the measurements.

Commits

  • a6ee4314 WIP: Nat range analysis and sunk sum tests
  • fcb5f02b Nat bounds: range analysis drops limit tests, sunk sums tested at loop exit
  • c3bdea6a Nat bounds: sunk sums off by default (collatz level overall)
  • 2f884449 Nat bounds: a parameter a loop steps down goes to 0 at once; other bounds widen after 64 walks (isqrt's Newton step keeps y >= 1)
  • 7c7195da Nat bounds: drop the sunk-sum tests (kept on opt/nat-tests-sink)
  • 420b991d perf(comp): memos keyed by a term no longer keep a unit's terms; arm_self builds back's node once
  • a9965e24 perf(comp): a match's arms are walked for re-formed nodes once, not every round
  • ffcd2688 perf(comp): nv_book's relation rounds walk only a def whose relations moved
  • 2909a635 fix(port): the Nat bounds and the arm walk memos type-check; selfs wrapped

🤖 Generated with Claude Code

nicolas-abril and others added 9 commits December 1, 2026 22:03
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e8c3983)
…p exit

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 58c43ab)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a4e15f8)
…unds widen after 64 walks (isqrt's Newton step keeps y >= 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2f4091e)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 0629568)
…self builds back's node once

A unit's emission builds terms (instantiated arms, arm_self's copies) that
die with it, but the memos keyed by a term kept every one: perceus/deriv's
literal matches left 5.5M entries in ground alone, 2.1 GB live after c_units
on main and over the 4,096 MB cap on opt/integration. The memos whose values
hold terms or probes (opens, teles, cols, etas, consts' inner maps) are
WeakMaps; the pure ones (ground, uses, spines) stay Maps, cleared when a
unit starts with over MEMO_MAX = 2^18 entries (as WeakMaps their millions of
entries slowed every GC: awfy/json's emit 1.9 s -> 3.2 s). arm_self compared
each node with a fresh back(ps), a chain of 32+ nodes per call; it is built
once per length of ps. The emitted C is byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit a99025b)
…very round

c_units emits every unit 3-4 times, and each emit_match walked its arms
again with a fresh self: mat_lits compared each U32 level's default with
the one it covers (term_same of two instantiated arms), arm_self walked
every arm for nodes it re-forms, and path_use counted self's uses down
every path. mat_lits now keeps which levels answer for themselves with
the match (FL.wlits); arm_self keeps a walk that re-formed nothing with
the arm (FL.selfs), with the node back built for each length of ps it
compared against, and a later call whose back builds the same nodes takes
it; an arm with no self in it keeps its path test (FL.dead), and the test
is a boolean that stops at the first answer (path_pos, for path_use > 0).
clo_refs walks an array's items by index, without a key array.
Same C on the 2,129-program corpus; perceus/deriv emits in 11.9 s
instead of 15.4 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 0a54062)
… moved

The relation rounds walk every def until no walk changes a relation; a
walk in them reads no state but the def's own relations (E is all top,
calls answer top, and the relations it sets for a callee are recomputed
from all its sites whenever one changes). A def whose relations are the
ones its last walk started from is not walked again, which drops most of
the round that only confirms. Same C on the 2,129-program corpus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 97674ad)
…apped

nv_step reads the divided Var's index through a cast, nv_rel_fix types
its pairs before the filter, and mat_lits' plan is a LitPlan, so its rows
are not implicitly any. The selfs field is wrapped under 80 columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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