Skip to content

Kernel: physical-equality fast paths in conversion's compare_under#22299

Merged
coqbot-app[bot] merged 1 commit into
rocq-prover:masterfrom
olympichek:conversion-fast-path-pr
Jul 24, 2026
Merged

Kernel: physical-equality fast paths in conversion's compare_under#22299
coqbot-app[bot] merged 1 commit into
rocq-prover:masterfrom
olympichek:conversion-fast-path-pr

Conversation

@olympichek

Copy link
Copy Markdown
Contributor

Kernel: physical-equality fast paths in conversion's compare_under

About

compare_under is the syntactic pre-check that lets conversion accept two closures without invoking the reduction machine. It walked both terms structurally even when they were physically identical, and treated matching Case/Fix/CoFix nodes as an unconditional failure (an explicit todo), forcing identical match-bearing terms through full reduction.

Overview

Changes introduced in this PR:

  • Adds a physical-equality shortcut: when both terms are the same pointer (c1 == c2) under substitutions and universe instances that are equal — or both trivial — the two closures are immediately convertible, with no structural walk.
  • Adds structural comparison of Case/Fix/CoFix nodes, replacing the old -> false (* todo some other time *) catch-all.
  • Added changelog (kernel performance improvement, type Changed).

`compare_under` is the syntactic pre-check that lets conversion accept two
closures without invoking the reduction machine. It walked both terms
structurally even when they were physically identical, and treated
matching Case/Fix/CoFix nodes as an unconditional failure (an explicit
"todo"), forcing identical match-bearing terms through full reduction.

Add a physical-equality shortcut (same term pointer under equal, or both
trivial, substitutions and universe instances is immediately convertible)
and structural comparison of Case/Fix/CoFix nodes. Both only strengthen a
sufficient acceptance condition — each new case implies the two sides are
literally equal — so they can accept but never reject, preserving the
conversion relation.

On a telescope-heavy kernel check where 95% of compare_under calls compare
a term against itself, this roughly halves the check.
@olympichek
olympichek requested a review from a team as a code owner July 23, 2026 12:43
@coqbot-app coqbot-app Bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Jul 23, 2026
@SkySkimmer

Copy link
Copy Markdown
Contributor

@coqbot bench

@coqbot-app

coqbot-app Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🏁 Bench results:

┌─────────────────────────────────────┬─────────────────────────┬───────────────────────────────────────┬──────────────────────────┐
│                                     │      user time [s]      │           CPU instructions            │  max resident mem [KB]   │
│                                     │                         │                                       │                          │
│            package_name             │   NEW      OLD    PDIFF │      NEW             OLD        PDIFF │   NEW      OLD    PDIFF  │
├─────────────────────────────────────┼─────────────────────────┼───────────────────────────────────────┼──────────────────────────┤
│                             coq-vst │  813.22   838.53  -3.02 │  6045565644078   6312138608106  -4.22 │ 2166748  2172824   -0.28 │
│          rocq-metarocq-translations │   16.17    16.48  -1.88 │   113750686610    113812347586  -0.05 │  887244   884612    0.30 │
│                            coq-core │    2.75     2.79  -1.43 │    19061588759     19069731222  -0.04 │   92952    92992   -0.04 │
│ coq-neural-net-interp-computed-lite │  235.12   236.47  -0.57 │  2258712273775   2262395792702  -0.16 │  885196   885180    0.00 │
│                    coq-math-classes │   81.70    82.01  -0.38 │   493445450608    493727347933  -0.06 │  515172   514636    0.10 │
│                        coq-bedrock2 │  356.91   357.76  -0.24 │  2918852262783   2932269230016  -0.46 │  872384   870768    0.19 │
│               rocq-metarocq-erasure │  436.29   436.80  -0.12 │  2951243971733   2956867844913  -0.19 │ 1805164  1746424    3.36 │
│               coq-engine-bench-lite │  126.57   126.68  -0.09 │   937915399072    939105367891  -0.13 │ 1104684  1108780   -0.37 │
│                            coq-hott │  159.78   159.91  -0.08 │  1063842299370   1064788084534  -0.09 │  471104   466904    0.90 │
│                        coq-compcert │  305.00   305.23  -0.08 │  1973664827433   1977550910936  -0.20 │ 1203536  1199220    0.36 │
│                       coq-fiat-core │   55.99    56.03  -0.07 │   335640162864    335820700350  -0.05 │  483300   483092    0.04 │
│                    coq-fiat-parsers │  272.32   272.41  -0.03 │  2073236981535   2082904865508  -0.46 │ 2037400  2270304  -10.26 │
│                 rocq-metarocq-pcuic │  599.87   600.03  -0.03 │  3817664839050   3838288461286  -0.54 │ 1694416  1766612   -4.09 │
│        coq-fiat-crypto-with-bedrock │ 7211.35  7207.45   0.05 │ 58779655111225  58869985347929  -0.15 │ 2827132  2827192   -0.00 │
│              rocq-metarocq-template │   81.53    81.48   0.06 │   553592791783    554665347283  -0.19 │ 1091056  1091376   -0.03 │
│                         rocq-stdlib │  240.24   240.09   0.06 │  1489041933480   1489986489726  -0.06 │  762160   759988    0.29 │
│                         coq-coqutil │   47.03    46.99   0.09 │   288838401813    288988442877  -0.05 │  563456   565088   -0.29 │
│           rocq-metarocq-safechecker │  311.10   310.53   0.18 │  2304732562540   2308762567251  -0.17 │ 1719400  1725468   -0.35 │
│                        rocq-runtime │   76.76    76.56   0.26 │   554965985779    554873215662   0.02 │  495964   495348    0.12 │
│                 coq-category-theory │ 1124.34  1121.23   0.28 │  8186018442005   8191909199982  -0.07 │ 6749212  6749096    0.00 │
│                        coq-coqprime │   55.66    55.50   0.29 │   381378342736    381491613187  -0.03 │  830556   830548    0.00 │
│          coq-performance-tests-lite │  871.12   868.52   0.30 │  6954373035366   6954173715860   0.00 │ 1570672  1469756    6.87 │
│                         coq-unimath │ 1955.21  1948.95   0.32 │ 15967995394142  15984693145783  -0.10 │ 1799688  1711740    5.14 │
│                        coq-rewriter │  329.29   328.15   0.35 │  2427126862413   2428784286505  -0.07 │ 1424168  1436472   -0.86 │
│                   coq-iris-examples │  369.13   367.42   0.47 │  2383607678802   2393743161023  -0.42 │ 1064172  1077464   -1.23 │
│         coq-rewriter-perf-SuperFast │  463.83   461.56   0.49 │  3531093765148   3531600414249  -0.01 │ 1265580  1294048   -2.20 │
│                           coq-color │  228.59   227.43   0.51 │  1436013492515   1439666275343  -0.25 │ 1163572  1169916   -0.54 │
│                rocq-metarocq-common │   41.37    41.16   0.51 │   263825588102    265398759252  -0.59 │  908228   916044   -0.85 │
│                        rocq-bignums │   25.40    25.21   0.75 │   159443888280    159367139535   0.05 │  463360   458852    0.98 │
│                 rocq-metarocq-utils │   24.39    24.15   0.99 │   154776338747    155148514348  -0.24 │  594008   582452    1.98 │
│                           rocq-core │    6.90     6.83   1.02 │    41484907871     41522589878  -0.09 │  446096   447620   -0.34 │
│                      rocq-equations │    7.83     7.72   1.42 │    54606500074     54669375481  -0.12 │  399708   400248   -0.13 │
└─────────────────────────────────────┴─────────────────────────┴───────────────────────────────────────┴──────────────────────────┘

INFO: failed to install
rocq-elpi (in NEW) (incompatible overlay merge)

rocq-mathcomp-boot (dependency rocq-elpi failed)
rocq-mathcomp-order (dependency rocq-elpi failed)
rocq-mathcomp-ssreflect (dependency rocq-elpi failed)
rocq-mathcomp-finite-group (dependency rocq-elpi failed)
rocq-mathcomp-algebra (dependency rocq-elpi failed)
rocq-mathcomp-solvable (dependency rocq-elpi failed)
rocq-mathcomp-field (dependency rocq-elpi failed)
rocq-mathcomp-group-representation (dependency rocq-elpi failed)
coq-mathcomp-odd-order (dependency rocq-elpi failed)
coq-mathcomp-analysis (dependency rocq-elpi failed)
coq-corn (dependency rocq-elpi failed)
coq-coquelicot (dependency rocq-elpi failed)
coq-fourcolor (dependency rocq-elpi failed)

🐢 Top 25 slow downs
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                            TOP 25 SLOW DOWNS                                                            │
│                                                                                                                                         │
│  OLD     NEW     DIFF   %DIFF    Ln                     FILE                                                                            │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│   43.7    45.4  1.7399   3.98%   578  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/compiler/src/compiler/MMIO.v.html                  │
│   49.4    50.5  1.1157   2.26%   376  coq-unimath/UniMath/ModelCategories/Generated/LNWFSMonoidalStructure.v.html                       │
│   1.37    2.38  1.0100  73.82%   574  coq-fiat-crypto-with-bedrock/src/Bedrock/P256/Jacobian.v.html                                     │
│   47.1    48.0  0.9475   2.01%   277  coq-fiat-crypto-with-bedrock/src/Bedrock/P256/Jacobian.v.html                                     │
│   14.8    15.7  0.8923   6.02%   833  coq-unimath/UniMath/CategoryTheory/ComprehensionCats/CwfFromCompCatWithUniv.v.html                │
│   76.8    77.7  0.8815   1.15%    20  coq-fiat-crypto-with-bedrock/src/Rewriter/Passes/NBE.v.html                                       │
│   24.6    25.3  0.7194   2.92%   550  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/bedrock2/src/bedrock2Examples/insertionsort.v.html │
│   19.4    20.1  0.6382   3.28%   543  coq-unimath/UniMath/CategoryTheory/Presheaves/SigmaTypes.v.html                                   │
│   89.0    89.5  0.5525   0.62%   968  coq-performance-tests-lite/src/fiat_crypto_via_setoid_rewrite_standalone.v.html                   │
│   40.1    40.7  0.5351   1.33%  1423  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/compiler/src/compiler/FlatToRiscvFunctions.v.html  │
│   26.6    27.1  0.5348   2.01%    34  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/MontgomeryLadderRISCV.v.html              │
│   16.9    17.4  0.5051   2.98%   905  coq-unimath/UniMath/ModelCategories/Generated/LNWFSCocomplete.v.html                              │
│   27.0    27.5  0.4768   1.77%   794  coq-fiat-crypto-with-bedrock/src/Bedrock/Secp256k1/JoyeLadder.v.html                              │
│   24.8    25.2  0.4741   1.91%   550  coq-bedrock2/bedrock2/src/bedrock2Examples/insertionsort.v.html                                   │
│   89.2    89.6  0.4391   0.49%   999  coq-performance-tests-lite/src/fiat_crypto_via_setoid_rewrite_standalone.v.html                   │
│   21.2    21.6  0.4231   1.99%   338  coq-unimath/UniMath/ModelCategories/Generated/LNWFSMonoidalStructure.v.html                       │
│ 15.861  16.283  0.4220   2.66%  1515  coq-vst/floyd/VSU.v.html                                                                          │
│   4.32    4.73  0.4108   9.52%   526  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/EdwardsXYZT.v.html                        │
│   4.71    5.11  0.3999   8.49%   580  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/EdwardsXYZT.v.html                        │
│ 15.887  16.282  0.3950   2.49%  1223  coq-vst/floyd/Component.v.html                                                                    │
│    102     102  0.3784   0.37%    22  coq-fiat-crypto-with-bedrock/src/Rewriter/Passes/ArithWithCasts.v.html                            │
│   37.9    38.2  0.3716   0.98%   244  coq-fiat-crypto-with-bedrock/src/Bedrock/P256/Coord32.v.html                                      │
│   28.5    28.9  0.3521   1.23%    31  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/MontgomeryLadderRISCV.v.html              │
│   3.68    3.99  0.3071   8.35%   554  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/EdwardsXYZT.v.html                        │
│   16.5    16.8  0.3032   1.84%   669  coq-fiat-crypto-with-bedrock/src/Bedrock/Secp256k1/JacobianCoZ.v.html                             │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
🐇 Top 25 speed ups
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                               TOP 25 SPEED UPS                                                                │
│                                                                                                                                               │
│  OLD     NEW     DIFF     %DIFF    Ln                      FILE                                                                               │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 35.353  29.757  -5.5960  -15.83%   147  coq-vst/veric/expr_lemmas4.v.html                                                                     │
│  5.681   0.223  -5.4580  -96.07%  1177  coq-vst/veric/expr_lemmas.v.html                                                                      │
│   5.61    0.22  -5.3900  -96.08%  2434  coq-vst/veric/semax_call.v.html                                                                       │
│  5.732   0.344  -5.3880  -94.00%  2883  coq-vst/veric/semax_call.v.html                                                                       │
│  34.27  29.288  -4.9820  -14.54%   194  coq-vst/veric/expr_lemmas4.v.html                                                                     │
│   68.2    64.0  -4.2727   -6.26%   608  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/bedrock2/src/bedrock2Examples/lightbulb.v.html         │
│   67.3    65.6  -1.7547   -2.61%   608  coq-bedrock2/bedrock2/src/bedrock2Examples/lightbulb.v.html                                           │
│   13.8    12.1  -1.7434  -12.62%   216  coq-fiat-crypto-with-bedrock/src/Fancy/Barrett256.v.html                                              │
│   16.7    15.0  -1.6661   -9.97%     6  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/deps/riscv-coq/src/riscv/Proofs/DecodeEncodeCSR.v.html │
│   8.19    7.28  -0.9048  -11.05%   571  coq-fiat-crypto-with-bedrock/src/Bedrock/P256/Jacobian.v.html                                         │
│    201     200  -0.8462   -0.42%     8  coq-neural-net-interp-computed-lite/theories/MaxOfTwoNumbersSimpler/Computed/AllLogits.v.html         │
│   1.08   0.250  -0.8337  -76.91%   928  coq-unimath/UniMath/CategoryTheory/ComprehensionCats/CwfFromCompCatWithUniv.v.html                    │
│   28.8    28.3  -0.5186   -1.80%   145  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/GarageDoorTop.v.html                          │
│   2.37    1.86  -0.5079  -21.41%   930  coq-neural-net-interp-computed-lite/theories/TransformerLens/HookedTransformer/Module.v.html          │
│   27.0    26.5  -0.5048   -1.87%   148  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/GarageDoorTop.v.html                          │
│   12.0    11.5  -0.5038   -4.20%   118  coq-fiat-parsers/src/Parsers/Refinement/SharpenedJSON.v.html                                          │
│  0.543   0.041  -0.5020  -92.45%    74  coq-vst/veric/expr_lemmas2.v.html                                                                     │
│   42.7    42.2  -0.4869   -1.14%   539  coq-fiat-crypto-with-bedrock/src/Bedrock/End2End/X25519/EdwardsXYZT.v.html                            │
│   35.7    35.2  -0.4703   -1.32%   898  coq-fiat-crypto-with-bedrock/src/Bedrock/Secp256k1/JoyeLadder.v.html                                  │
│   18.7    18.3  -0.4515   -2.41%    32  coq-performance-tests-lite/src/pattern.v.html                                                         │
│   4.36    3.96  -0.4062   -9.31%   190  coq-unimath/UniMath/Algebra/Universal/Examples/Tests.v.html                                           │
│   20.4    20.0  -0.3902   -1.91%     6  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/deps/riscv-coq/src/riscv/Proofs/DecodeEncodeI.v.html   │
│   2.50    2.14  -0.3537  -14.17%   323  coq-fiat-crypto-with-bedrock/src/Bedrock/P256/RecodeProofs.v.html                                     │
│  0.342   0.018  -0.3240  -94.74%   421  coq-vst/veric/expr_lemmas2.v.html                                                                     │
│   10.6    10.3  -0.3178   -3.01%  2300  coq-fiat-crypto-with-bedrock/rupicola/bedrock2/compiler/src/compiler/FlatToRiscvFunctions.v.html      │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

@SkySkimmer

Copy link
Copy Markdown
Contributor

@coqbot run full ci

@coqbot-app coqbot-app Bot removed the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Jul 24, 2026
@coqbot-app

coqbot-app Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🔴 CI failure at commit c9b523d without any failure in the test-suite

✔️ Corresponding job for the base commit 3403def succeeded

❔ Ask me to try to extract a minimal test case that can be added to the test-suite

🏃 @coqbot ci minimize will minimize the following target: ci-jasmin
  • You can also pass me a specific list of targets to minimize as arguments.

@herbelin

herbelin commented Jul 24, 2026

Copy link
Copy Markdown
Member

Note: this PR divides by 2 the time of some very long Defined in the "bonak" formalisation of parametricity-based simplicial sets (from 15mns to 7mns, in a branch also assuming #22272, if I remember correctly).

@olympichek

Copy link
Copy Markdown
Contributor Author

Note: this PR divides by 2 the time of some very long Defined in the "bonak" formalisation of parametricity-based simplicial sets (from 15mn to 7mns, in a branch also assuming #22272, if I remember correctly).

Yes, the original motivation for this PR is to improve performance of Rocq on the work-in-progress formalization of extension of the Bonak's semi-simplicial set construction to semi-simplicial groupoids. This change gives a ~2x improvement, a reduction from ~15 min to ~7 min on my laptop, also assuming #22272 change. The exact problematic Defined is here (it alone accounts for most of ~15 min): SemiSimplicialGpd.v#L1232

@SkySkimmer SkySkimmer self-assigned this Jul 24, 2026
@SkySkimmer SkySkimmer added the kind: performance Improvements to performance and efficiency. label Jul 24, 2026
@SkySkimmer SkySkimmer added this to the 9.4+rc1 milestone Jul 24, 2026

@SkySkimmer SkySkimmer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine to me
@ppedrot WDYT?

@ppedrot

ppedrot commented Jul 24, 2026

Copy link
Copy Markdown
Member

Assuming I haven't missed some subtle invariant, the change looks good to me.

@SkySkimmer

Copy link
Copy Markdown
Contributor

@coqbot merge now

@coqbot-app
coqbot-app Bot merged commit 8414b2c into rocq-prover:master Jul 24, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: performance Improvements to performance and efficiency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants