Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] performance question: replace autorewrite by reflection?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] performance question: replace autorewrite by reflection?


Chronological Thread 
  • From: Jason Gross <jasongross9 AT gmail.com>
  • To: coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] performance question: replace autorewrite by reflection?
  • Date: Wed, 29 Jul 2020 22:51:51 -0400
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-ej1-f47.google.com
  • Ironport-phdr: 9a23:S48tXROew2m3O+nD+GUl6mtUPXoX/o7sNwtQ0KIMzox0I/39rarrMEGX3/hxlliBBdydt6sazbSL+PywEUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe8bL9oLRi7rQrdu8YVjIB/Nqs/1xzFr2dSde9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLYTQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVRjnhjoaNz4i6GHYlNB/jL5VrhKmohxw2Y/UYIeIP/Z6ca7QedYWSGxcVchTSiNBGJuxYIQBD+UDPehWoYrzqUYQoxSiHgSjHv/jxyVSi3PqwaE30eIsGhzG0gw6GNIOtWzZotHvO6cJVuC1yrTDwzTZb/NRwjf985XDfxcjof6WRrJwdszRyUY1FwPClVWQsojoMiia1uQIqWeb7u5gWfizhG4grgF8uz6izdojhYfVnIwa0EzE9Tlnz4YvI921UEB1bN6nHZZQtiyWKol7T8AmTm9nuSs3xaMLtYClcSUFx5opxx3SZuGDfoaH7R/tWuifLSl8iXxldr+yiAu//Eumx+bhWMe011NKoTBEktnKrn0N0h3T6tSdRvRj40ihxC6D1w/S6uFYIUA0iLHUJ4Q9zb43k5ofqUvDHi7qmEX2ka+ZbV8o+umv6+nhf77opYecOpdqhg3iNqkigM+yDOQiPgQQQmSW+v6w2bLh8ED/Xb5ElOc5krPDv5DfPckbprC2AwtS0os77hawFTam0NABkXYZLlJJZQuLj4bmNlzMOvz4AvC/g1OjkDdv2f/KJKHuApLILnTbkbfhe6hy61JExQYt0dxS44hYB7IBLf7pREP9qd/VAgU2PgG22+rnDc9y1oIaWWKBGK+ZN6bSvEeK5u01OOmMY4kVuDnnK/gi/P7ulns0lEQSfamsx5QXaXS4Eu56LEWeZHrgms0BHnsSvgoiUOzqj0WPXiJUZ3arRq4z+jU7CJ+9AorYXYCsgLmB3D+hEZFMZ2BGDEqMEXbyeImeVfcMcnHaHsg0mTsdELOlVoVpgRqprUrxz6dtBuvS4CwR85z5gotb/erWwDM77jtyR+uH1HqWBzV2l3gPQTAs27tk8GRyz16C1e5zhPkORo8b3O9ATgpvbc2U9Od9Ed2nBlOYIoW5DW2+S9DjOgkfC8oryoZXMUl4EtSmyBvE2njyWu5Hp/mwHJUxt5nk8T30Lsd5xWzB0fB43VYjS8pLc2ahg/wmrlWBN8vyi0yc0p2SW+Ec0SrKrjrRyGOPuARVUlc1X/maG38YYUTSoJLy4UaQF7I=

This is actually the topic of a recent draft of mine, recently (re)submitted to POPL 2021.

Some background: One of the biggest bottlenecks in the rewrite tactics is the allocation of evars (in particular, the allocation of evar contexts) when instantiating lemmas.  This shows up mostly when you have a large context or many binders in the goal, and issues such as #12524 (setoid_rewrite and rewrite_strat are cubic in the number of binders even when there are no matches) and #12510 are about this.  Separately, even when there are no matches and no binders, autorewrite, rewrite, rewrite!, and rewrite? are all quadratic in the size of the goal (#12600).  So I would not say that autorewrite is already optimized, and I believe there are a number of relatively low-hanging fruit.

Second: Getting a proof term that does not incur overhead which is quadratic (or worse) in the number of rewrites is highly non-trivial; you may find the "Performance Bottlenecks of Proof-Producing Rewriting" section (Appendix A) of the aforementioned paper enlightening.

Given this, there is reason (and evidence) to expect that using a reflective procedure will speed things up for you.  I believe Rtac (see, e.g., Gregory Malecha's thesis) has a general reflective rewriter (though I was not able to make it work in recent versions of Coq, and development seems to be abandoned), and the rewriting engine that I created for fiat-crypto, which is the subject of the aforementioned POPL submission, is another example of such a general engine.  Unfortunately, I cannot in good conscience suggest that you use the framework that I built as anything other than an example; it suffers from a number of restrictions that could be lifted with engineering work (such as the fact that while any type without arguments is supported, the only type families supported are option and prod), and, more importantly, it's unmaintainable in its current form and should be rewritten from scratch.

Hope this helps,
Jason


On Wed, Jul 29, 2020 at 7:14 PM jonikelee AT gmail.com <jonikelee AT gmail.com> wrote:
Using Ltac profiling, it looks like about 40% of time spent in one
project I have is within autorewrite, the remainder primarily doing
proof search. The particular autorewrite hint dbs are not large (10 or
so rules each, one has only 3 rules) and the addition of rules ends
before the hint dbs are used. In such cases, would it be advantageous to
create a reflective procedure to replace use of autorewrite by a
particular hint db?  Or is this unlikely to improve performance,
considering that autorewrite is already optimized (presumably)?  I do
not beleive that Qeds are significantly time consuming in this project,
so I don't think shrinking the proof terms will have much benefit.




Archive powered by MHonArc 2.6.19+.

Top of Page