Skip to content

perf(comp): memoize pure self-recursive defs on small word domains through a table (stacked on the compile-time PR) - #68

Draft
nicolas-abril wants to merge 3 commits into
opt/compile-speedfrom
opt/memo-tables
Draft

nicolas-abril wants to merge 3 commits into
opt/compile-speedfrom
opt/memo-tables

Conversation

@nicolas-abril

Copy link
Copy Markdown
Owner

On main (6180be5b)

This PR is a port onto main, stacked on opt/compile-speed: 3 commits of its own, with no integration history (head c15f0f83).
It replaces #54.

Port notes

  • Stacked on the compile-time PR: memo reads its Nat ranges (nv_book) to size its tables. Without them it tabled 3 of 8 osprey programs; with them 6 of 8. The token count includes the compile-time PR's.
  • memo's probe runs the compiler's own front passes through one function, book_passes(), shared with compile_book; it no longer names passes. When perf(comp): one specializer: a call copies its callee for the lambdas and constants it passes (replaces #31, #52, #2) #53 (closure pass) and the literal fold land, their passes go into book_passes, and memo then tables tak too (8 of 8, confirmed in a scratch build).
  • Tabled on this stack (fib, coins, pascal; bend and bend-par): 628M-3213M instructions -> 12-13M, outputs correct. tak: not yet (see above).
  • Verified locally instead of on the cluster (the cluster connection layer kept failing for this run): every program compiled against the compile-time PR, and every test whose C changed (10) passes on the C and JS lanes.

Checks

  • Cluster gate: not run (see below).
  • 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: +13688 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

  • 4ede335d perf(comp): memoize pure self-recursive defs on small word domains
  • c1a29284 fix(port): memo's probe runs this branch's passes: file_book and nv_book
  • c15f0f83 fix(port): memo's probe runs compile_book's passes through book_passes

🤖 Generated with Claude Code

nicolas-abril and others added 3 commits December 1, 2026 22:24
A def that calls itself twice or more along one path, on words, answering a
word (fib, binomials, change-making, tak) goes through a table keyed by its
arguments, filled on the first call. The table spans the Nat intervals
nv_book proves on a probe of the book (acc_def and def_fix off), a Bool's or
fieldless enum's constructors, or a window of the small values of a Nat no
self call raises (none passing a constant). The def becomes a wrapper whose
ops say miss, hit or outside; a call outside the table runs as before. One
pool of at most 2^20 entries (2^18 per def), result + 1 per entry, written
whole so racing threads store the same value. Defs a bang call reaches, or
that reach one, are left alone; on the device the ops say outside.

Tests: tests/run/memo_{window,offset,enum,deep,par,huge,bang,impure_array}.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 521f7a1)
The probe ran the integration's pipeline (clo_book, cf_book, and acc_def
and def_fix kept off by an mprobe flag); this branch's compile_book runs
file_book then nv_book, so the probe runs those two and the flag goes.
BEND_MEMO is read through globalThis, which needs no Node types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
compile_book's passes over the book before C is emitted (file_book and
nv_book here) are one function, book_passes, which memo's probe runs too:
a front pass added there (the closure pass, literal folding) reaches the
probe without naming it, so memo's domains grow with what has landed (tak
gets its table only once clo_book and cf_book run). The emitted C is the
same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nicolas-abril added a commit that referenced this pull request Dec 1, 2026
…passes (#68)

The passes over the book before C is emitted are one function, called by
compile_book and by memo's probe, as in #68 (memo on main): memo's probe
no longer names them. The C is unchanged (fib, coins, pascal, tak, the tar
demo, memo_window, clo_elim and lit_fold byte-identical).

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