Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize list constructions in micromega #10745

Closed
wants to merge 2 commits into from

Conversation

ppedrot
Copy link
Member

@ppedrot ppedrot commented Sep 10, 2019

This PR reduces the number of list allocations in Micromega by using accumulators. On the example from #10743, the failure time is divided by almost 2, from ~18.5s to ~10.5s. There is probably a way to optimize even better, but for the time being this looked like a nice enhancement.

Bench running here.

We prevent reallocating a lot of lists by threading the result of a fold
function inside an accumulator.

Includes the Micromega bootstrap.
This part of the code has no theorems about it, so it is more perilous to
to preserve the same behaviour as before. Accumulator logic is bad for your
brain.

Also includes a Micromega bootstrap.
@ppedrot ppedrot added the kind: performance Improvements to performance and efficiency. label Sep 10, 2019
@ppedrot ppedrot added this to the 8.11+beta1 milestone Sep 10, 2019
@ppedrot ppedrot requested a review from a team as a code owner September 10, 2019 15:04
@ppedrot
Copy link
Member Author

ppedrot commented Sep 11, 2019

Bench shows nothing interesting.

┌────────────────────────┬─────────────────────────┬─────────────────────────────────────────────┬─────────────────────────────────────────────┬───────────────────────────────┬────────────────────────────┐
│                        │      user time [s]      │                 CPU cycles                  │              CPU instructions               │     max resident mem [KB]     │         mem faults         │
│                        │                         │                                             │                                             │                               │                            │
│           package_name │     NEW     OLD PDIFF   │               NEW               OLD PDIFF   │               NEW               OLD PDIFF   │        NEW        OLD PDIFF   │     NEW     OLD    PDIFF   │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│              coq-verdi │  119.66  120.16 -0.42 % │      332313768758      333618862570 -0.39 % │      418792028202      418759287246 +0.01 % │     560008     559996 +0.00 % │      13      79   -83.54 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│               coq-hott │  390.02  391.27 -0.32 % │     1063434087022     1063421817663 +0.00 % │     1610829432215     1610844431082 -0.00 % │     583716     583676 +0.01 % │     460     251   +83.27 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│         coq-coquelicot │   76.28   76.42 -0.18 % │      210402403465      210399013720 +0.00 % │      255158968604      255170774357 -0.00 % │     669712     669748 -0.01 % │     213      15 +1320.00 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│       coq-math-classes │  217.07  217.39 -0.15 % │      607420342687      607256523947 +0.03 % │      769634936631      769668074247 -0.00 % │     515020     514880 +0.03 % │      25      18   +38.89 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│   coq-mathcomp-algebra │  164.86  165.10 -0.15 % │      459830983003      459823943575 +0.00 % │      568454472375      568470058863 -0.00 % │     635184     635096 +0.01 % │      15      19   -21.05 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│         coq-verdi-raft │ 1324.66 1326.10 -0.11 % │     3694576279190     3699717227733 -0.14 % │     5001275724072     5001487908038 -0.00 % │    1812216    1812016 +0.01 % │     126      35  +260.00 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│        coq-lambda-rust │ 1532.43 1532.88 -0.03 % │     4271223624045     4272319860780 -0.03 % │     5654130993011     5654075263100 +0.00 % │    1491924    1466100 +1.76 % │      41       1 +4000.00 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│           coq-compcert │  783.89  783.92 -0.00 % │     2183548428415     2184301143907 -0.03 % │     2931440921317     2931047228704 +0.01 % │    1067328    1067360 -0.00 % │     229     275   -16.73 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│             coq-geocoq │ 1575.95 1575.65 +0.02 % │     4397704427495     4397892017071 -0.00 % │     6447016374665     6447023382830 -0.00 % │    1366724    1366320 +0.03 % │     245     166   +47.59 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│       coq-fiat-parsers │  646.83  646.61 +0.03 % │     1810593242438     1808864236489 +0.10 % │     2727061316502     2727025822777 +0.00 % │    3193660    3201828 -0.26 % │     325     696   -53.30 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│  coq-mathcomp-solvable │  189.18  189.10 +0.04 % │      527295650951      527311262925 -0.00 % │      704706779077      704682924629 +0.00 % │     774012     773916 +0.01 % │       4      49   -91.84 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│              coq-flocq │  463.55  463.32 +0.05 % │     1289582453577     1288969683604 +0.05 % │     1783251964923     1783107433258 +0.01 % │    1118084    1118076 +0.00 % │     267     101  +164.36 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│               coq-corn │ 1459.20 1458.46 +0.05 % │     4073981924099     4071512133421 +0.06 % │     6025798306859     6025833881295 -0.00 % │     873732     873716 +0.00 % │       1      49   -97.96 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│  coq-mathcomp-fingroup │   51.55   51.52 +0.06 % │      143500683319      143495986194 +0.00 % │      186791337780      186808362159 -0.01 % │     565752     564004 +0.31 % │       4       0     +nan % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│          coq-fourcolor │ 2181.46 2180.06 +0.06 % │     6080379717535     6079847366707 +0.01 % │    11360675635792    11360592697636 +0.00 % │     930508     930396 +0.01 % │      20       1 +1900.00 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│              coq-color │  718.46  717.94 +0.07 % │     2006249249812     2007777113805 -0.08 % │     2394705546244     2394682407557 +0.00 % │    1385108    1384868 +0.02 % │     104     198   -47.47 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│ coq-fiat-crypto-legacy │ 6333.68 6328.48 +0.08 % │    17638508193773    17625494564462 +0.07 % │    28588682488519    28568776784706 +0.07 % │    2391160    2393312 -0.09 % │     901    1211   -25.60 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│ coq-mathcomp-odd-order │ 1445.76 1444.30 +0.10 % │     4028510824563     4026428453852 +0.05 % │     6858113531290     6858052930546 +0.00 % │    1244780    1244796 -0.00 % │      36      38    -5.26 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│        coq-fiat-crypto │ 3836.10 3831.43 +0.12 % │    10656706400530    10647311407129 +0.09 % │    16662981928493    16666055149030 -0.02 % │    2351072    2347852 +0.14 % │    1203     928   +29.63 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│ coq-mathcomp-character │  182.56  182.33 +0.13 % │      508615108345      508559963626 +0.01 % │      670824763227      670825625202 -0.00 % │     897352     897260 +0.01 % │      88      49   +79.59 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│     coq-mathcomp-field │  230.80  230.42 +0.16 % │      643157794660      642546075488 +0.10 % │      917212004886      917136890596 +0.01 % │     741196     741360 -0.02 % │       0      32  -100.00 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│            coq-unimath │ 4051.82 4044.93 +0.17 % │    11286538524727    11273159131830 +0.12 % │    20814019963679    20814583175781 -0.00 % │    1828236    1805412 +1.26 % │     512     282   +81.56 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│          coq-fiat-core │  112.47  112.21 +0.23 % │      319916830882      320105900777 -0.06 % │      399145165591      399153806008 -0.00 % │     495472     495276 +0.04 % │     503     275   +82.91 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│            coq-bignums │   69.24   68.86 +0.55 % │      189834791955      189925095254 -0.05 % │      252838362028      252807444914 +0.01 % │     490668     490520 +0.03 % │     134     141    -4.96 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│             coq-sf-plf │   44.48   44.18 +0.68 % │      124262251759      124111197658 +0.12 % │      160761651048      160761161350 +0.00 % │     492640     483352 +1.92 % │      45      11  +309.09 % │
├────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼────────────────────────────┤
│ coq-mathcomp-ssreflect │   40.26   39.87 +0.98 % │      111214454516      110944316204 +0.24 % │      134927230072      134926109645 +0.00 % │     528288     528316 -0.01 % │     103      26  +296.15 % │
└────────────────────────┴─────────────────────────┴─────────────────────────────────────────────┴─────────────────────────────────────────────┴───────────────────────────────┴────────────────────────────┘

I guess nobody is using Lia in extreme cases.

@samuelgruetter
Copy link
Contributor

bedrock2 is missing in the benchmark, I guess that's because at the time this bench was run, our build was failing, but now it should work again, according to the ticks of our own CI.

But I think bedrock2's current code would not run faster, because we avoid using lia in these extreme cases. @andres-erbsen built his own abstract interpretation based on intervals for this, but it would really be great to be able to call lia without having to worry wether it will run fast enough or not.

And in fiat-crypto, if I understand correctly (/cc @JasonGross), it would simplify the proofs scripts if they could run Z.div_mod_to_equations before each call to lia, but that turned out to be infeasably slow. (Note that the slow goal I posted in #10743 also was generated by Z.div_mod_to_equations).

So to summarize, I guess the reason nobody is using Lia in extreme cases is that Lia doesn't work in extreme cases at the moment.

@ppedrot
Copy link
Member Author

ppedrot commented Sep 20, 2019

I have a hard time rebasing this after the merge of the zify PR. I might try reimplementing it from scratch.

@vbgl vbgl added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Sep 20, 2019
@pi8027 pi8027 added the part: micromega The lia, nia, lra, nra and psatz tactics. Also the legacy omega tactic. label Sep 23, 2019
@ppedrot
Copy link
Member Author

ppedrot commented Oct 2, 2019

Closing the PR in the meantime.

@ppedrot ppedrot closed this Oct 2, 2019
@coqbot coqbot removed this from the 8.11+beta1 milestone Oct 2, 2019
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. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. part: micromega The lia, nia, lra, nra and psatz tactics. Also the legacy omega tactic.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants