-
Notifications
You must be signed in to change notification settings - Fork 6
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
List.rev is unexpectedly quadratic #10
Comments
Interesting, I also didn't know that (math-comp has a rev function that is documented as linear-time). I'm surprised that your suggestion is to document the problem rather than fixing it. Can you say why? |
I'm guessing that making proofs about rev compatible across versions would be a bit of a pain. But that doesn't mean we shouldn't do it.
I discovered this performance issue a while back (I think around the time I noticed math-comp redefining rev), and since have been using |
Replacing the definition of
I suspect that numerous user proofs implicitly rely on that conversion. Since I'm not personally relying on Coq's standard library List module, I don't want to be the one blamed for encouraging a backward-incompatible changes. |
This is probably known to a number of Coq developers, but I discovered only yesterday, after 15 years of using Coq, that
List.rev
is implemented with quadratic complexity. That could explain numerous of the performance bottleneck that I, and others, have encountered.I then saw that Coq.Lists.List also defines a
rev'
function, with the proper tail-rec definition. But I don't recall seeing it used in any Coq script that I have looked at.I suggest to better advertise the issue with the definition of
rev
. At the very least, I guess there should be a comment above the definition ofrev
, and possibly also at the top of the file.Another possibility for tracking down problematic usages would be to develop a profiler version for coqc , that could, among other things, measure the length of arguments of
rev
and report a warning whenever the length exceeds a couple dozen elements. Such a profiler could be exploited by users who want their scripts to run faster, suggesting hints for improvements.To see how bad the quadratic behavior gets in practice, I ran the following benchmark. Even for short lists, the computation time is significant.
The text was updated successfully, but these errors were encountered: