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

Extremely slow prettyprinting for lists of tuples #1274

Closed
brianhuffman opened this issue Sep 2, 2021 · 4 comments · Fixed by #1276
Closed

Extremely slow prettyprinting for lists of tuples #1274

brianhuffman opened this issue Sep 2, 2021 · 4 comments · Fixed by #1276
Labels
exponential slowdown Extreme performance problems

Comments

@brianhuffman
Copy link
Contributor

In the current master version (5a6f9a0) this expression takes 5 seconds to evaluate at the REPL on my machine:

[ (x : Integer, x) | x <- [1..26]]

The runtime is exponential in the length, doubling with each additional element in the list. Length 28 takes about 22 seconds on my machine.

The type of x doesn't seem to matter much. Changing the type to Z 30 also takes 5 seconds. At type [8] it takes 13 seconds. Replacing one of the xs with another expression like True or () doesn't affect the time. The same slowdown occurs with a two-element record or a two-element array, although a one-element record or array makes it evaluate quickly. Going up to three elements makes it moderately slower (but definitely not 3^n slower).

@brianhuffman brianhuffman added the exponential slowdown Extreme performance problems label Sep 2, 2021
@brianhuffman
Copy link
Contributor Author

brianhuffman commented Sep 2, 2021

It looks like the slowdown does not occur in cryptol-2.7.0, cryptol-2.8.0, cryptol-2.10.0, or cryptol-2.11.0.

@brianhuffman
Copy link
Contributor Author

I just finished doing a bisection. Git says that 35bb83b is the first bad commit.

Turns out it's not evaluation, it's the prettyprinter.

@brianhuffman brianhuffman changed the title Extremely slow evaluation for some lists of tuples Extremely slow prettyprinting for lists of tuples Sep 2, 2021
@brianhuffman
Copy link
Contributor Author

Profiling shows that function layoutWadlerLeijen.best from module Prettyprinter.Internal is where almost all the runtime is spent. The number of entries is in the hundreds of millions.

@brianhuffman
Copy link
Contributor Author

It appears that the exponential slowdown can be eliminated by replacing layoutSmart with layoutPretty in src/Cryptol/Utils/PP.hs. I'm not sure whether this leads to any undesirable differences in printed output.

brianhuffman pushed a commit that referenced this issue Sep 3, 2021
This avoids an exponential slowdown that occurs with `layoutSmart`
in combination with nested lists or lists of tuples.

Fixes #1274.
@brianhuffman brianhuffman linked a pull request Sep 3, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exponential slowdown Extreme performance problems
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant