Skip to content

perf: compare a pair again after a stopped try with no unfold - #355

Merged
tamnd merged 5 commits into
mainfrom
perf/v-try-full
Dec 2, 2026
Merged

tamnd merged 5 commits into
mainfrom
perf/v-try-full

Conversation

@tamnd

@tamnd tamnd commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Part of #354.

Problem

v_try_struct compares the arguments of two applications with a work bound of TRY_WORK. If this bound stops the compare, it gives false, because a later unfold usually finds the equality. But if no side can unfold, as Eq Bool (decide p) true against Eq Bool true true in a decide proof, the lazy delta loop ends at once and nothing compares the arguments again. So engine V gives false for two equal values, and engine R checks the declaration again from the start. nano-lean and the official kernel always finish this compare.

Change

  • v_eq_core keeps the pair of the last compare that stopped on the bound of v_try_struct. If the loop ends with the same pair and no step after the loop changes it, v_retry_struct compares the pair again.
  • The retry can use at most 1<<23 work and 256 MiB of arena growth. A stop on this bound stops the check, and engine R checks the declaration. Engine R is faster than engine V on a long closed computation, so a retry with no bound made magma-list-pair-n21 and gf3-matrix-product slower.
  • In a retry, v_spent also checks the arena size, because a Nat computation can grow the arena with few unfolds.
  • Spec perf/19.31 gives the comparison with the rivals, the measures and the decision.

Measures

Build without PGO, perf stat -e instructions:u, one thread, on server4.

Test v0.11.0 This PR
magma-list-deep-n36 28.20 G 7.93 G
grind-field-kernel-cancel 23.70 G 5.96 G
magma-list-pair-n21 9.71 G 15.47 G
gf3-matrix-product 19.12 G 20.05 G
short-circuit-and-bad 22.12 G 23.94 G
init 45.48 G 46.11 G
std 82.64 G 83.37 G
Sum of the 44 perf tests 127.72 G 96.63 G (-24.3%)

The loss on init comes from declarations where engine V is slower than engine R. A larger depth bound makes it worse (spec perf/19.31.4).

Checks

  • The 238 Arena tests give the expected verdicts.
  • The 452 tests of the workspace pass, cargo clippy --workspace --all-targets -D warnings is clean, and cargo xtask all passes.

tamnd added 4 commits December 2, 2026 16:49
When the compare of the arguments in v_try_struct stops on its bound, engine V takes the false as a guess that an unfold finds the equality. If no side can unfold after the stop, nothing compared the arguments in full, so engine V gave a false that is not a result and declined the check. Now v_eq_core compares this pair again with the bound of the check.
The retry after a stopped try can use at most 1<<22 work and 128 MiB of arena growth. A retry that stops on these bounds stops the check, and engine R checks the declaration.
The retry can use at most 1<<23 work and 256 MiB of arena growth. Inside the retry, v_spent also checks the arena size, because a long Nat computation can grow the arena with few unfolds.
Spec perf/19.31 compares engine V with the rivals test by test, gives the gap in v_eq_core, the measures of the fix and of its bound, and the decision. The code comments name v_retry_struct.
@tamnd tamnd added this to the M14 Perf: closed computation milestone Dec 2, 2026
@tamnd tamnd added area/core The type checker: engines F and R, declarations, profiles type/perf Fewer instructions, less memory or less wall time labels Dec 2, 2026
The two changelog lines of the retry name #355.
@tamnd
tamnd merged commit c71f9ba into main Dec 2, 2026
27 of 29 checks passed
@tamnd
tamnd deleted the perf/v-try-full branch December 2, 2026 14:01
This was referenced Dec 2, 2026
tamnd added a commit that referenced this pull request Dec 2, 2026
This PR makes the release v0.11.1. The release is a step of the
milestone M14 (#354).

The PR sets the version to 0.11.1 in `Cargo.toml`, `Cargo.lock` and
`fuzz/Cargo.lock`, and adds the changelog entry. The code change of this
release is #355: engine V compares a pair again when its compare stopped
on the bound of `v_try_struct` and no side of the pair can unfold. On a
build without PGO, the sum of the 44 perf tests goes from 127.72 G to
96.63 G instructions. `--confirm all` gives 0 disagreements on `init`,
`std` and the Arena tests, and each Arena test gives the expected exit
code.

Part of #354.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core The type checker: engines F and R, declarations, profiles type/perf Fewer instructions, less memory or less wall time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant