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

Use local persistent data structures for VM global tables #12640

Merged
merged 9 commits into from Jan 12, 2022

Conversation

ppedrot
Copy link
Member

@ppedrot ppedrot commented Jul 4, 2020

This is a PR I had lying on my drive, which is a first step towards being able to dynamically change the opacity of constants in the VM (#4476, #5660). In a nutshell, this removes the use of global mutable data structures used in the VM in favour of local persistent ones.

There is still a main global entry point to the table, but eventually it should be stored immutably in the kernel environment.

@ppedrot ppedrot added the kind: cleanup Code removal, deprecation, refactorings, etc. label Jul 4, 2020
@ppedrot ppedrot added this to the 8.13+beta1 milestone Jul 4, 2020
@ppedrot ppedrot requested review from a team as code owners July 4, 2020 11:35
@ppedrot
Copy link
Member Author

ppedrot commented Jul 4, 2020

Here is a bench:

┌─────────────────────────────┬─────────────────────────┬─────────────────────────────────────────────┬─────────────────────────────────────────────┬───────────────────────────────┬───────────────────┐
│                             │      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-mathcomp-odd-order │ 1131.83 1178.02 -3.92 % │     3150985440623     3281225295472 -3.97 % │     5098770022261     5098720376193 +0.00 % │    1267920    1269280 -0.11 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│            coq-fiat-parsers │  674.30  685.88 -1.69 % │     1892958698625     1924030521839 -1.61 % │     2783395115537     2783292879904 +0.00 % │    3588332    3580548 +0.22 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                coq-coqprime │   86.41   87.02 -0.70 % │      239066833661      240142492051 -0.45 % │      323111865823      323010431520 +0.03 % │     764480     765156 -0.09 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                  coq-geocoq │ 1518.95 1528.61 -0.63 % │     4237913560453     4264661734051 -0.63 % │     6328069535369     6327931867834 +0.00 % │    1215736    1215552 +0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│       coq-mathcomp-solvable │  175.47  176.52 -0.59 % │      489182475157      490984588062 -0.37 % │      695871449388      695977402334 -0.02 % │     787712     787844 -0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                         coq │  557.37  560.16 -0.50 % │     1562908875428     1570828453546 -0.50 % │     2138971440206     2138822369687 +0.01 % │     602708     602712 -0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                 coq-coqutil │   61.25   61.55 -0.49 % │      170434549656      171596887950 -0.68 % │      212940904534      212958430833 -0.01 % │     529196     528840 +0.07 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                    coq-corn │ 1658.75 1666.40 -0.46 % │     4624978445296     4643712107864 -0.40 % │     6968983343721     6968726151295 +0.00 % │     887704     887880 -0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│        coq-mathcomp-algebra │  142.34  142.98 -0.45 % │      396427304540      397840549549 -0.36 % │      520214559784      520236315195 -0.00 % │     615024     614672 +0.06 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│             coq-lambda-rust │ 1520.00 1526.56 -0.43 % │     4235024985911     4251209898242 -0.38 % │     6083446374608     6085237275255 -0.03 % │    1202984    1205140 -0.18 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                coq-bedrock2 │  226.36  227.33 -0.43 % │      629534888537      631589966375 -0.33 % │     1026326006257     1026800089317 -0.05 % │    1090936    1090748 +0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                  coq-sf-plf │   43.64   43.82 -0.41 % │      122334426683      122652364122 -0.26 % │      168121747539      168088817745 +0.02 % │     502472     508664 -1.22 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│      coq-mathcomp-character │  163.54  164.16 -0.38 % │      454604499905      456406737513 -0.39 % │      634474571865      634434211684 +0.01 % │     810888     810688 +0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                   coq-verdi │  120.32  120.76 -0.36 % │      333752448781      334425217680 -0.20 % │      419000376347      418968491697 +0.01 % │     561400     561664 -0.05 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│               coq-fourcolor │ 2524.65 2532.99 -0.33 % │     7033076138625     7064608358419 -0.45 % │    11584492431745    11582537639948 +0.02 % │     875088     875004 +0.01 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│      coq-mathcomp-ssreflect │   52.92   53.02 -0.19 % │      145254672072      145460624102 -0.14 % │      189966798378      189920628191 +0.02 % │     571404     573168 -0.31 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│              coq-verdi-raft │ 1268.70 1270.70 -0.16 % │     3535995979184     3538843915818 -0.08 % │     4969138528100     4967944301150 +0.02 % │     977452     977600 -0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│          coq-mathcomp-field │  263.80  264.14 -0.13 % │      734686044780      735758054504 -0.15 % │     1124130848300     1124154307897 -0.00 % │     792404     792216 +0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                 coq-unimath │ 4061.70 4065.29 -0.09 % │    11301904267923    11311664402750 -0.09 % │    21521293227869    21524800975233 -0.02 % │    1006172    1006024 +0.01 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│       coq-mathcomp-fingroup │   49.58   49.58 +0.00 % │      137215666883      137796374407 -0.42 % │      191732938690      191725110084 +0.00 % │     551736     551428 +0.06 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                    coq-hott │  309.23  309.12 +0.04 % │      835859052200      833979619785 +0.23 % │     1334225685554     1334102235802 +0.01 % │     630608     630632 -0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│               coq-fiat-core │  110.60  110.55 +0.05 % │      318645982709      318213112941 +0.14 % │      418762997667      418762232940 +0.00 % │     488064     488048 +0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│              coq-coquelicot │   74.18   74.11 +0.09 % │      203361901823      203438071909 -0.04 % │      266876001485      266839031294 +0.01 % │     659792     659932 -0.02 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                 coq-bignums │   58.60   58.41 +0.33 % │      161606203183      162024854030 -0.26 % │      219335264412      219267290408 +0.03 % │     468316     468308 +0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                   coq-color │  676.50  674.25 +0.33 % │     1891196344707     1883378494476 +0.42 % │     2313901817330     2313970356929 -0.00 % │    1154208    1153788 +0.04 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│ coq-rewriter-perf-SuperFast │ 1039.17 1035.36 +0.37 % │     2890667877321     2879933915829 +0.37 % │     4583538745879     4582078223605 +0.03 % │    1056004    1056008 -0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│       coq-performance-tests │ 1954.37 1943.20 +0.57 % │     5448508610190     5412393572533 +0.67 % │    10152552430345    10146479811891 +0.06 % │    4315932    4316240 -0.01 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│            coq-math-classes │  217.60  215.98 +0.75 % │      607892821513      603392730700 +0.75 % │      797724757802      797680395773 +0.01 % │     511688     510660 +0.20 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                coq-compcert │  713.21  704.19 +1.28 % │     1985093326244     1961930871340 +1.18 % │     2672294370547     2672046458225 +0.01 % │    1077076    1077032 +0.00 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│             coq-fiat-crypto │ 5356.59 5281.62 +1.42 % │    14877829351521    14675268535411 +1.38 % │    24639190640806    24654545485020 -0.06 % │    2401564    2397404 +0.17 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│            coq-engine-bench │ 6393.52 6293.11 +1.60 % │    17845745052652    17564882893622 +1.60 % │    31416591123476    31424301311267 -0.02 % │    4316008    4316236 -0.01 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                coq-rewriter │  599.60  590.16 +1.60 % │     1666812550613     1639757845946 +1.65 % │     2481569126560     2481166728120 +0.02 % │     985292     963480 +2.26 % │    0    0  +nan % │
├─────────────────────────────┼─────────────────────────┼─────────────────────────────────────────────┼─────────────────────────────────────────────┼───────────────────────────────┼───────────────────┤
│                   coq-flocq │  178.80  175.77 +1.72 % │      496334291061      488642476154 +1.57 % │      598255342088      598272918349 -0.00 % │     904160     904600 -0.05 % │    0    0  +nan % │
└─────────────────────────────┴─────────────────────────┴─────────────────────────────────────────────┴─────────────────────────────────────────────┴───────────────────────────────┴───────────────────┘

Some developments are very slightly slower, and mathcomp got quite faster for some reason.

kernel/csymtable.ml Outdated Show resolved Hide resolved
@SkySkimmer SkySkimmer requested a review from a team July 4, 2020 11:48
kernel/csymtable.ml Outdated Show resolved Hide resolved
@ppedrot ppedrot force-pushed the vm-persistent-global branch 3 times, most recently from bdfc8a6 to 6aaff98 Compare July 11, 2020 11:28
@ppedrot
Copy link
Member Author

ppedrot commented Jul 28, 2020

This needs an assignee. @SkySkimmer maybe?

@SkySkimmer
Copy link
Contributor

This is more for VM people. @maximedenes ?

@SkySkimmer SkySkimmer removed request for a team August 18, 2020 10:55
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Aug 27, 2020
@coqbot-app coqbot-app bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Aug 27, 2020
@maximedenes
Copy link
Member

This is more for VM people. @maximedenes ?

Yes, I'll take it.

@maximedenes maximedenes self-assigned this Aug 31, 2020
@maximedenes
Copy link
Member

@ppedrot Would you mind rebasing? I gave priority to #12894 because it was an important fix, but I'll try to take care of this one too.

@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Sep 24, 2020
@coqbot-app coqbot-app bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Sep 24, 2020
@ppedrot
Copy link
Member Author

ppedrot commented Sep 24, 2020

@maximedenes Done.

This is only used for VM slots now. Instead of an imperative hashtable,
we use a similar immutable structure.
We store the VM definitions inside a persistent array for efficiency
while emulating immutability.
This prevents haphazard access to the global table.
We encapsulate types that are only used internally using opaque types.
@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

@silene done, but I insist that this is a bad idea that will have to go away at some point anyways.

@silene
Copy link
Contributor

silene commented Jan 11, 2022

I am confused. Are you talking about global_table or are you talking about something else? Regarding global_table, it certainly needs to be removed at some point. But at least it is no longer accessed by eval_to_patch, thanks to your pull request. And I don't see why this code would need to change again, whichever way we choose to propagate the table from vm.ml to vnorm.ml.

By the way, why did you remove the error message from set_strategy? Is it raised elsewhere now?

@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

I don't see why this code would need to change again

Well, there is the infamous call to patch which involves a higher-order call to an imperative closure. I think that we should split dependency computation from VM evaluation and turn this into a pure closure just fetching the slot. But it's not trivial and will require some serious disentanglement.

why did you remove the error message

I don't remember that part. Maybe it's raised elsewhere, maybe not, let me check.

@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

Nope, indeed the error message went away. I'll reintroduce it even though it's not clear that it's complete (e.g. why don't we also fail on section variables is a mystery). Currently the checks are spread around, there are calls in tactics.ml and vernacentries.ml, I think I'll go with the latter since it's a user-facing message.

@ppedrot ppedrot requested a review from a team as a code owner January 11, 2022 12:27
@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

@silene fixed

@silene
Copy link
Contributor

silene commented Jan 11, 2022

there is the infamous call to patch which involves a higher-order call to an imperative closure.

But the closure does not survive the call to patch, does it? And since it is defined right before the call, it seems like a sensible use case. Or are you arguing that computation of relocations should be the job of eval_to_patch (or some other function) rather than patch itself?

@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

are you arguing that computation of relocations should be the job of eval_to_patch

Yes. We are interleaving steps of relocation computation with VM evaluation in the same call. There used to be a frightening comment about concurrent mutation of the bytecode, which was not true anymore since we switched to a pure string API. But still, the fact that we're calling arbitrary code when trying to find indices inside a table is not very reassuring to me.

@silene
Copy link
Contributor

silene commented Jan 11, 2022

We are interleaving steps of relocation computation with VM evaluation in the same call.

Do we? I thought the code was first fully relocating the bytecode and then evaluating it. Even with strong normalization, there should be no reason to relocate again some already relocated bytecode.

@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

I am not sure we're talking about the same thing, we should probably discuss it more interactively at some point.

@ppedrot ppedrot added this to the 8.16+rc1 milestone Jan 11, 2022
@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

CI failure is real, it's perennial trying to set a Qed definition transparent. My my, I'll tweak this to the most stupid backwards compat patch ever so that we can fix the check in a distinct PR.

The API let the user believe that there was a way to modify the opacity
status of individual constants although this was a total lie.
Some of them were outdated, some of them were in French.
This is a purely diplomatic step, my personal belief is that this is
marginally worse but I will not die on that hill.
@ppedrot
Copy link
Member Author

ppedrot commented Jan 11, 2022

Hopefully we're good this time.

@silene
Copy link
Contributor

silene commented Jan 12, 2022

@coqbot merge now

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Jan 12, 2022

@silene: You can't merge the PR because you're not among the assignees.

@silene silene self-assigned this Jan 12, 2022
@silene
Copy link
Contributor

silene commented Jan 12, 2022

@coqbot merge now

@coqbot-app coqbot-app bot merged commit fe4f979 into coq:master Jan 12, 2022
@ppedrot ppedrot deleted the vm-persistent-global branch January 12, 2022 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: cleanup Code removal, deprecation, refactorings, etc. part: VM Virtual machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants