[GHC] #7850: Strangely high memory usage on optimized Ackermann function

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: x86_64 (amd64) Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Greetings. The following post on stack overflow demonstrates some strange behavior in, at least, recent GHC versions (7.4.2 on): [http://stackoverflow.com/questions/16115815/ackermann-very-inefficient- with-haskell-ghc] The program in question is simple: {{{ main = print $ ack 4 1 ack :: Int -> Int -> Int ack 0 !n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) $ ack m (n-1) }}} Here are the properties I've been able to deduce so far: 1) When compiled without optimizations, the program uses almost no memory, but of course takes a while. 2) When compiled with optimizations (-O and above), the program eats memory at a staggering rate. It easily freezes my machine in a matter of seconds. 3) -ddump-simpl reveals that the loop is completely unboxed, operating only on Int#. -ddump-prep also shows no lets where allocation would presumably happen. 4) Setting a maximum heap size typically seems to have no effect. When I set it to the minimum heap size with -M4096, even the optimized program seems to run in constant space most of the time. However, using something like -M1000000 seems to result in the outrageous memory usage, and the RTS never catches that far more than 1 megabyte of memory is being used. I had to convince myself that the flag actually does something with another test program. 5) The standard bounded stack also does nothing. So, we seem to have a program that is allocating vast amounts of (ostensibly) non-heap, non-stack memory; but only when optimized. I believe I once set the maximum heap to 40960B, and killed the program before it killed my machine. On exiting, I got a heap overflow error. So, my initial stab would be that the completely unboxed loop somehow ''is'' allocating in the heap, but somehow not in a way that ever allows the garbage collector or heap overflow check to run (similar to how a non- allocating loop can block any thread preemption). That's a wild guess, though. I'm unable to easily investigate the behavior on older GHC versions, unfortunately. So I'm unsure how far back this behavior goes. If I've missed something obvious, I apologize, but this seems like very odd behavior to me. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: x86_64 (amd64) Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by Artyom.Kazak): * cc: Artyom.Kazak@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by Artyom.Kazak): * architecture: x86_64 (amd64) => Unknown/Multiple Comment: This bug is reproducible on my laptop (Linux, x86). I was not able to run the optimised program with less than 64kb of heap, though (was getting `Heap exhausted` errors), but running it with `-M64000` resulted in fifteen minutes of freeze and this error message: {{{internal error: getMBlock: mmap: Operation not permitted}}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by Khudyakov): I've tried GHC 7.0.4, 7.2.2 7.4.2 and 7.6.2 on x64. All except 7.0.4 consume a lot of memmory. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by monoidal): Looks fixed in HEAD. I can reproduce out-of-memory in 7.6.2 but not 7.7. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by nomeata): My observation is that with `-kc1M`, thinks work great (37 MB memory in use). With `-kc786k` I can already observe the bad memory behaviour, but it still finishes (15251 MB). `-kc512k` almost immediately fills up my memory. My guess is that for some reason, unused stack chunks are not freed by the GC. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by refold): * cc: the.dead.shall.rise@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by nomeata): Maybe https://github.com/ghc/ghc/commit/03d360f289a1c7e93fedf8cfa274cbe5929cd32c fixed it? (Just a guess, I did not set up a bisect environment.) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by refold): This program should probably be added to tests or benchmarks. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: MacOS X | Architecture: x86_64 (amd64) Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by adinapoli): * os: Linux => MacOS X * architecture: Unknown/Multiple => x86_64 (amd64) Comment: If It might be of any help, I reproduced it on Mac OS X 10.8 with GHC 7.6.2 as well. Profiling reveals an humongous allocation of Pinned Memory: http://heap.ezyang.com/view/6fb7441b501c00f428126f6b6e767d2412f43c2c#form -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by adinapoli): * os: MacOS X => Unknown/Multiple * architecture: x86_64 (amd64) => Unknown/Multiple -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Changes (by supki): * cc: matvey.aksenov+ghctrac@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by dolio): The benchmarks game used to have an entry called 'recursive' that ran fib, ack and tak.* But it's since disappeared, and isn't one of the entries that was copied into nofib. ack is the only one that displays the pathological behavior by default. I thought tak might, but it didn't. This seems to be related to a shallower stack usage. For instance, tak 60000 30 15 runs comfortably (for a very long time) with -K32K, so it will never overflow the default chunk size. However, one can get tak to eat memory in a similar way by making the stack chunking small enough. For (an extreme) instance -kb25 -kc256, setting the chunk size to 256 bytes, will cause the same memory exhausting behavior. This meshes with nomeata's observations above. Also for reference, I just built 7.6.3, and whatever fixed this in HEAD has not been incorporated into it. It still displays the pathological behavior. ---- [*] tak is defined as follows: {{{ tak x y z | y < x = tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y) | otherwise = z }}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by dolio): Oh, another note: this behavior still happens when using the llvm backend. That probably casts some doubt that it was the commit nomeata mentioned, as that appears to be all changes to the ncg. I don't know the code's structure though, so I can't say definitively. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ------------------------------------+--------------------------------------- Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Runtime performance bug | Blockedby: Blocking: | Related: ------------------------------------+--------------------------------------- Comment(by refold): Replying to [comment:9 adinapoli]:
If It might be of any help, I reproduced it on Mac OS X 10.8 with GHC 7.6.2 as well. Profiling reveals an humongous allocation of Pinned Memory:
http://heap.ezyang.com/view/6fb7441b501c00f428126f6b6e767d2412f43c2c#form 35KiB could be hardly called humongous. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonmar): * cc: simonmar (added) * difficulty: => Unknown -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by dolio): I've now built HEAD, and get the same results as monoidal. Both ack and tak run in constant memory even with very small stack chunk sizes. When using -kc2M, HEAD-built ack actually runs slower than 7.6.x -kc2M. And default -kc is quite a bit slower than that, but still much better than freezing the machine. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by carter): * cc: carter.schonwald@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by adinapoli): Replying to [comment:14 refold]:
35KiB could be hardly called humongous.
Fair enough, but that was just for half a second of execution, and compared to the other allocation it seemed quite a lot to me. I've tried to do more profiling, but apparently running it with +RTS -hc does not takes GBs of memory very quickly, it has linear increases but then it comes back to relatively small values. I'm a bit puzzled. If I run the same executable without flags, it literally eat up my memory in seconds. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

I'm a bit puzzled. If I run the same executable without flags, it
#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by refold): Replying to [comment:18 adinapoli]: literally eat up my memory in seconds. Yes, I also noticed that. Running the program with heap profiling enabled makes the problem go away. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by PHO): * cc: pho@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by applicative): No one seems to be pointing out that this this program ''does'' return and more importantly ''gives the correct answer'' on `ghc-7.6.2`. On this dubious macbook air (osx 10.8, 4gb , 2.4ghz, 2 cores etc), the world does not end, this wiki does not freeze, my files are not threatened; it takes as much memory as the os is willing to give it -- ~2gb -- and looks like so: {{{ $ ghc -O2 ackermanbug.hs -fforce-recomp # ghc-7.6.2 64bit $ time ./ackermanbug 65533 real 1m47.372s; user 0m26.577s; sys 0m17.641s }}} The distinction between `real` and `user` is of course suggestive of pathology -- but not a bug in the strict sense -- and is indeed handsomely repaired in {{{ $ khc -O2 ackermanbug.hs -fforce-recomp # ghc HEAD $ time ./ackermanbug 65533 real 0m24.081; user 0m23.920s; sys 0m0.133s }}} If I add the news that "ack n 1 = n + 2", ghc does fine in either version; and of course it clunks along never to return with `ack 4 2`. **With the same emendation http://hpaste.org/86212 the vaunted `gcc` gives a segmentation fault instantly**. What I wonder is whether gcc's segfault is a 'bug' we should be hysterically reporting on the gcc trak, or if the `gcc` devs just put in an ack-detector because they got tired of people whining about such things, preferring to focus on what matters. What is more interesting is that e.g. `ocamlopt` takes 5s for `ack 4 1` where `ghc-HEAD` takes 24s. I cannot replicate the superiority the SO guy found with the `gcc` . It seems about the same as `ocamlopt`. If I add ''any help at all'' to the program, e.g. that ack 1 = (+2) -- ghc becomes, for all actually calculable arguments, just as fast as gcc. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by dolio): Here's the simplest test case I can think of to demonstrate the behavior: {{{ -- main = print $ stk 4051 1000000 main = print $ stk 4052 1000000 stk :: Int -> Int -> Int stk _ 0 = 0 stk depth n = loop depth `seq` stk depth (n-1) loop :: Int -> Int loop 0 = 0 loop n = loop (n-1) `seq` 0 }}} With -O0, ~0% memory usage. With -O2, memory usage grows about linearly with time. If the alternate main is used, -O2 also uses ~0% memory. The boundary can be found using +RTS -K32K, which will stack overflow after one chunk is used. Choices of depth that do not overflow under such a setting will run in little memory, and choices that do will use large amounts of memory. The boundary number will probably be higher when running with 4-byte ints, for instance. Some +RTS -s stats look like: 4052 -O2: 32259 MB total memory in use (504 MB lost due to fragmentation) 4052 -O0: 1 MB total memory in use (0 MB lost due to fragmentation) 4051 -O2: 1 MB total memory in use (0 MB lost due to fragmentation) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by adinapoli): Replying to [comment:21 applicative]:
No one seems to be pointing out that this this program ''does'' return and more importantly ''gives the correct answer'' on `ghc-7.6.2`. On this dubious macbook air (osx 10.8, 4gb , 2.4ghz, 2 cores etc), the world does not end, this wiki does not freeze, my files are not threatened; it takes as much memory as the os is willing to give it -- ~2gb -- and looks like so:
Don't know which version of the program you used but, on my Macbook, using ghc 7.6.2, 64bit, 16GB of Ram, with the program originally posted, running with -O2 hogs my computer, it takes 10GB of memory very quickly making my pc nearly unusable. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:23 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by awson): Most interesting is that while many notice `-kc1M` cure the problem they still insist it runs much slower than Ocaml version. But it is *NOT*! It takes less than 6.5 secs to deliver a correct answer for original unmodified version of ack with `-kc1M` on all my configs: Windows 8 64-bit on Q9450 2.66MHz:[[BR]] ghc-7.6.2 32-bit - 6.49 secs[[BR]] ghc-7.6.2 64-bit - 6.47 secs Windows 7 on i7-2675QM[[BR]] ghc-7.6.2 32-bit - 6.13 secs[[BR]] ghc-7.6.2 64-bit - 3.80 (!!!) secs (i tried this several times with the same result) Could it be GHC RTS on Windows which makes the difference? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by refold): Replying to [comment:24 awson]:
Most interesting is that while many notice `-kc1M` cure the problem they still insist it runs much slower than Ocaml version. But it is *NOT*!
Interesting to hear about this difference between platforms. On Linux (and apparently OS X) it just eats all memory and does not finish. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:25 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Replying to [comment:24 awson]:
Most interesting is that while many notice `-kc1M` cure the problem
#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by awson): Replying to [comment:25 refold]: they still insist it runs much slower than Ocaml version. But it is *NOT*!
Interesting to hear about this difference between platforms. On Linux
(and apparently OS X) it just eats all memory and does not finish. AFAIU on Linux and OS X `-kc1M` on 7.6.x makes memory consumption very good, but performance is still several times worse than that of Ocaml both for 7.6.x with `-kc1M` and HEAD (where this bug is declared to be fixed). Still, the performance is *several times* better under Windows for 7.6.x (sadly, there are no HEAD builds for Windows to try). -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:26 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by dolio): I can't speak for anyone else, but performance here (Linux, 64-bit) is much better with 1M stack chunks as well. Also, with the program I posted recently... It finishes very shortly after running into my swap with the given parameters. With depth=4050, it takes a little over 5 seconds. With depth=4051, it takes a little over 5 seconds. With depth=4052, it takes around 26 seconds. And this is still true on HEAD. Anyhow, the difference is that 4052 has to allocate a second stack chunk on each iteration, and then toss it away almost immediately. This activity dramatically slows down the program. -kc1M makes the same difference for the ackermann example. I wouldn't be surprised if OCaml doesn't have to do any similar fooling on this example (due to a larger initial stack), which is why it would perform comparably to C by default. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:27 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by lelf): * cc: anton.nik@… (added) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:28 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.6.3 Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonmar): * status: new => patch * milestone: => 7.6.3 Comment: As noted earlier, it's already fixed in master. I don't remember when I noticed the bug and fixed it, the fix seems to have come in with the giant patch to rewrite the RTS Cmm files in the new syntax. Anyway, attached is a patch for the 7.6 branch that fixes it. I'll let the release engineer decide what to do with it :-) -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:29 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7850: Strangely high memory usage on optimized Ackermann function ---------------------------------+------------------------------------------ Reporter: dolio | Owner: Type: bug | Status: merge Priority: normal | Milestone: 7.6.3 Component: Compiler | Version: 7.6.2 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime performance bug Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by igloo): * status: patch => merge -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7850#comment:30 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (2)
-
GHC
-
GHC