7

I am using the Prettier Printer implementation from the contrib library in Idris.

When I fold with the |//| operator on a list of Docs, the performance quickly explodes, i.e. the following code doesn't terminate before I lose my patience:

*IdrisFMT\PrettyDocs> :exec toString 0 15 $ fold (|//|) $ map text $ words "this is a long sentence with a lot of words that I can use for testing the performance of the prettier printer implementation. I need a few more words to prove my point, though."

Please note, the above fold is equal to the pre-defined combinator fillCat.

If I instead use the pre-defined cat combinator (= group . vcat), it terminates within a second:

*IdrisFMT\PrettyDocs> :exec toString 0 15 $ cat $ map text $ words "this is a long sentence with a lot of words that I can use for testing the performance of the prettier printer implementation. I need a few more words to prove my point, though."
"this\nis\na\nlong\nsentence\nwith\na\nlot\nof\nwords\nthat\nI\ncan\nuse\nfor\ntesting\nthe\nperformance\nof\nthe\nprettier\nprinter\nimplementation.\nI\nneed\na\nfew\nmore\nwords\nto\nprove\nmy\npoint,\nthough."

The Doc adt version of cat $ map text $ words "this is a long sentence with a lot of words that I can use for testing the performance of the prettier printer implementation. I need a few more words to prove my point, though." can be seen here: https://pastebin.com/4AJWcGnD

I understand that the cat combinator solves a much simpler problem, but I fail to see how fillCat is so complex as to never terminate.

Could this be caused by a mistake in the implementation, or am I simply constructing too complex a document?

EDIT

The definition of the |//| operator is found here: https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Text/PrettyPrint/WL/Combinators.idr#L65-L69

||| The document `(x |//| y)` concatenates document `x` and `y` with
||| a 'softbreak' in between. This effectively puts `x` and `y` either
||| right next to each other or underneath each other.
(|//|) : Doc -> Doc -> Doc
(|//|) = concatDoc softBreak
user2407038
  • 14,400
  • 3
  • 29
  • 42
Felix
  • 8,385
  • 10
  • 40
  • 59
  • I have no idea, but I wonder if that could be related to the quadratic blow-up that `++` has on lists when folded. IIRC `foldl' (++) [] listOfStrings` has a bad performance. Perhaps `fold (|//|)` has a similar issue? – chi Sep 03 '17 at 12:16
  • 1
    Please note that this is `Idris`, so I'm not even sure the same holds true here (afaik, strings are not lists in `Idris`). – Felix Sep 03 '17 at 12:19
  • could you include the definition of `|//|`. Also does the same problem happen if you compile instead of execute inside the interpreter? – epsilonhalbe Sep 03 '17 at 15:21
  • Are you getting the same behaviour with `fillCat` used directly? – Alec Sep 03 '17 at 15:39
  • fillCat is literally defined as fold (|//|) but yes I tried both. I'll add the operator definition when I'm back on my machine – Felix Sep 03 '17 at 16:05
  • @epsilonhalbe I have just tried compiling to a binary with the same result. Also, I'm pretty convinced that :exec does exactly that. – Felix Sep 03 '17 at 16:27

1 Answers1

1

This may not be an answer but it could give some hints to someone with a better understanding of prettyprint library. I used the Idris JVM bytecode backend to diagnose this as I am working on the backend and I was curious to see how it behaves on the JVM. Unsurprisingly the behavior was the same: the first snippet just hangs and the second one works but to debug, I was able to use the JVM tool, jvisualvm, to take the thread dump and profile CPU.

Here is the thread dump:

java.lang.Thread.State: RUNNABLE
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at main.Main.lambda$$lbraceText$dotPrettyPrint$dotWL$dotCore$dotrender$colonbest$colon0_lam_0$rbrace$26(Unknown Source)
        at main.Main$$Lambda$18/189568618.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at Text.PrettyPrint.WL.Core.render$colonbest$colon0(Unknown Source)
        at Text.PrettyPrint.WL.Core.lambda$render$1(Unknown Source)
        at Text.PrettyPrint.WL.Core$$Lambda$16/1531448569.call(Unknown Source)
        at io.github.mmhelloworld.idrisjvm.runtime.Runtime.unwrap(Runtime.java:37)
        at main.Main.main(Unknown Source)
        at main.Main.$lbracerunMain_0$rbrace(Unknown Source)
        at main.Main.main(Unknown Source)

CPU profiling result from jvisualvm: enter image description here

As we can see from the thread dump, this method call Text.PrettyPrint.WL.Core.render$colonbest$colon0 keeps repeating in the stack trace and, from the CPU profiling, that function is the top hot spot. This method corresponds to best function defined within render function of Text.PrettyPrint.WL.Core module available here. I am not much familiar with this code but it looks like the best function keeps calling itself without terminating the recursion.

Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
  • While this is interesting, I think I had already come to the same conclusion. It doesn't fit the performance characteristic described in Wadler's paper that's linear in the size of the document (the "document" can be seen here: https://pastebin.com/4AJWcGnD) At this point, I'm guessing there is some part of this implementation that doesn't follow the optimizations described in the paper. – Felix Sep 06 '17 at 10:41