Repository navigation
Description
Written with Claude Code (an AI agent), for the author of #1209.
What
Every bend f.bend --check-only re-checks the whole import closure of f.bend, so the cost of a file that adds one trivial law is the cost of everything it imports. A small repro, to show the effect and what #1209 does about it.
Repro
gen.py writes lib.bend (800 small proofs by computation) and ten tiny files that each import it and add one law:
# gen.py
lib = ["import Base", ""]
for i in range(800):
n = 1000 + (i * 7) % 2000
lib += [f"def shared_{i}() -> {{U32.to_nat({n}) == {n}n : Nat}}:", " {==}", ""]
open("lib.bend", "w").write("\n".join(lib))
for j in range(10):
open(f"client_{j}.bend", "w").write(
f"import Base\nimport ./lib.bend as Lib\n\n"
f"def mine_{j}() -> {{1n+{j}n == {j+1}n : Nat}}:\n {{==}}\n")
open("solo.bend", "w").write("import Base\n\ndef solo() -> {1n+1n == 2n : Nat}:\n {==}\n")python3 gen.py
ulimit -s 16384
time bend solo.bend --check-only # Base only
time bend lib.bend --check-only # the library alone
time bend client_0.bend --check-only # one trivial law on top of the library
for j in 0 1 2 3 4 5 6 7 8 9; do bend client_$j.bend --check-only; done
(The numbers are kept below about 3,000 because a single file with several 4,000+ literals gets close to the machine-stack limit; that is a separate issue.)
Measured
linux-x64, Bun 1.4.2, one run each. The machine was busy (load average about 20 from unrelated jobs), so read the numbers as rough.
| run | wall |
|---|---|
stock v2.0.34, solo.bend (Base only) |
0.14 s |
stock v2.0.34, lib.bend |
1.96 s |
stock v2.0.34, client_0.bend |
about 1.9 s |
| stock v2.0.34, ten clients one after another | 24.3 s |
Each client checks only one new law, but costs about as much as the whole library. Ten clients cost ten times the library.
With #1209 (module-cache, head e866bc9a, whose bend2/main.ts I confirmed is byte-identical to the build used):
| run | wall |
|---|---|
BEND_CACHE unset, client_0.bend |
1.84 s |
cold cache, client_0.bend |
1.87 s |
warm cache, client_0.bend |
0.11 s |
| warm cache, clients 1 to 9 one after another | 1.03 s total |
So the cache brings a file whose only new work is one trivial law from about 1.9 s to about 0.1 s, and without BEND_CACHE the behaviour is the same as before.
Why it matters
Any project that checks many files over a shared library pays this per file. In the project this came from (about 5,300 proof files), the per-file check spends most of its time on shared imports.
Not covered here
One machine, one run per row, busy host. This does not test cache invalidation or the soundness conditions; #1209 has its own gate for those (gates/cache.ts).
Activity
The module cache is on by default, in ~/.bend/checked, and book_valid…