You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A brief description
Managing haskell projects with the stack tool is unusable due to how slow it is.
Expected results
(from a laptop running ubuntu 16.04)
time stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
real 0m0.124s
user 0m0.092s
sys 0m0.036s
Actual results (with terminal output if applicable)
On desktop running WSL
time stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
real 0m50.520s
user 0m0.172s
sys 1m40.547s
Your Windows build number
15025
Steps / All commands required to reproduce the error from a brand new installation
After installation, need stack to pull in a version of GHC. This should do the trick.
stack setup
stack upgrade --install-ghc
time stack ghc -- --version
Strace of the failing command
Generating the strace output (attached) inludes a few long (multi-second) waits on FUTEX_WAIT, as well as one for mmap.
Required packages and commands to install
Install stack with the standard instructions
This is on our backlog but is unlikely to make the Creators Update. I know we're planning on looking at this soon though.
For some context, I've looked at what causes this slowdown. For some reason stack has mapped an mind-bogglingly huge region of memory (I'm talking dozens of terabytes). When we fork we walk the entire address range to set up the new process's state. We have a design that should vastly speed this up, but we're approaching "pencils down" date for Creators Update.
Reacted by therealkenc, Jack Hammons, George Pollard, Jihyeon Kim (김지현), Dmitry Sobinov, J Zhang, Bjorn, Ted Feng, Austin, Andrew Duffy and 1 more
I assume they're doing it to manage their own heap. It's a big "MAP_NORESERVE" region which Linux seems to intelligently handle since "allocate all the things" seems to be a common paradigm.
This seems to be the related discussion over at ghc ticket 9706 here, for what it is worth. Quoth:
BTW, I found that I could mmap 100 TB with PROT_NONE (or even PROT_READ) and MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED with no measurable delay, and I can start 10000 such processes at once, so there doesn't seem to be any significant cost to setting up the page table mappings (at least on my system). Not sure why that is, exactly. The VSZ column in ps looks quite funny of course :)
So by my math that's 100×1012×104 = 1018 ≅ 260, which gets you in just under the wire. Or something.
I have encountered a similar bug with plain ghc and pandoc. Really slow just to call and print out version info. Can confirm for slow-ring Insider Build & the Windows Preview v.15.15014 (using the free VM).
I found this slowdown by installing ghc v.8.0.2 (anything v.7.10 and below was fast) or by installing pandoc v.1.18 & above. See directions to install ghc or install pandoc for testing. If needed, I can provide a simple set of commands to reproduce.
They both run similarly slow/delayed for me on both systems, but I have not seen reports from other *nix users seeing similar slowdowns, so I am guessing this is WSL related.
This does not require Stack to replicate, GHC compiler alone is enough. I'm experiencing the same dreadfully slow compiler work. Besides, programs compiled with 8.0.x are slow too.
We have a shiny new two-step memory allocator for 64-bit platforms (see Trac #9706). In addition to simplifying the runtime system’s implementation this may significantly improve garbage collector performance. Note, however, that Haskell processes will have an apparent virtual memory footprint of a terabyte or so. Don’t worry though, most of this amount is merely mapped but uncommitted address space which is not backed by physical memory.
Reacted by Val Packett, Vanessa McHale, Bjorn, Fyodor Soikin, Ted Feng, Andrew Duffy, Xiyng and Ryan Newton
I was going to quip that curiosity too, but stuck with "awesome" instead. So you benchmark 8.0 and find out it is some percent faster than 7.0. Or just as fast, but simpler. But you end up demonstrating not much in the exercise. The Haskell guys seem okay with a hello world app asking for a terabyte of virtual memory. The Chakra guys seem okay with asking for 32GB to print hello, and if you are going to do that, [expletive], why not ask for a TB. I am still academically interested in how they arrived at 32GB. Why not 64GB or 128GB? Certainly not because "that would be crazy".
It's working code. Smart people thought it was a good idea. Shrug. What you gonna do except sigh and re-work the memory manager.
FWIW, Golang also does something similar by reserving a contiguous chunk of 512 GB of memory (see this comment).
I'm certainly not qualified enough to say how they came up with that number, other than that it's a power of two and—to use their words—"512 GB (MaxMem) should be big enough for now".
I have a workaround in the meantime, based on the discussion in https://ghc.haskell.org/trac/ghc/ticket/13304. It involves compiling your own GHC which does not utilize the large address space allocation, and then using that as the GHC for your stack builds. My workaround relies on then supplying that GHC as the common GHC for your projects. In my example, I will recompile GHC 8.0.2 using whatever ghc you already have on your system. I will also make sure that Cabal is installed using this GHC -- otherwise, installing other packages will fall under the same problem of slowness. I suggest cleaning your ~/.stack and other stack directories to make sure you don't have any GHC lying around with the large-allocation functionality.
To fix, in the bash environment, I ran
# install necessary prereqs if not there
sudo apt-get install ghc happy alex
cd
git clone -b ghc-8.0.2-release --recursive git://git.haskell.org/ghc.git ghc-8.0.2
cd ghc-8.0.2
./boot
./configure --disable-large-address-space #can set --prefix=... here
make -j8 #-j(number-of-threads)
sudo make install
sudo ln -s /usr/local/bin/ghc ~/.local/bin/ghc-8.0.2 #or wherever your prefix put the binaries
# link the rest of the binaries, like runghc, ghci, etc
# this is to make sure the "system-ghc" is properly called
echo "system-ghc: true" >> ~/.stack/config.yaml
cd
# optional Cabal and cabal-install reinstallation to conform to new ghc
stack install Cabal
stack install cabal-install
Now you can do your stack install and stack build in your projects, using the specially compiled GHC.
You can monitor the VIRT usage with something like top or htop. Try stack exec ghci and monitor VIRT before and after.
Reacted by Milán Nagy and Jordan Mackie
Reacted by Sebastian Graf, Joshua Grosso, Justin Le, Bjorn, Neil de Carteret, Philipp, Ted Feng and Milán Nagy
I have anecdotally found the same problem with tar, which is (I think) separate from the huge memory allocation slowness. When I untar a large tarball (let's say 10GB) in a Linux VM, it returns almost immediately, because I have 20GB of RAM assigned to the VM and it all ends up in cache at near memcpy() speed. With WSL it seems to rate limit on writes to disk. I did not report it because I don't untar large files that often, and limiting on writes to disk is hard to prove these days without low level instrumentation (ugh, effort). But from the blinkenlights it looks like that is what's happening. It doesn't seem to be a CPU limiting thing, because of inefficient stat() calls per the git slowness complaints, say.
[edit] Another data point is sync never seems to do anything in WSL. With the same 10GB untar in a VM, sync takes countable time to flush the cache.
Another anecdote: I opted into 17074 hoping to get acceptable working conditions, but stack setup took exactly an hour to complete (even with windows defender temporarily disabled). For comparison, stack setup under cmd.exe starting from scratch took ~4 minutes. I'll give working with the result a shot, but it doesn't look promising.
Sorry for the negative report; keep doing great work, you'll get there. ❤️
and then simply prepending /opt/ghc/bin/ to your $PATH env-var.
Reacted by Milán Nagy, Julian Birch, Simon Jakobi, Tao He, gurpreetshanky, Samir, Aaron Friel, Jordan Mackie, Robert Stefanic, Daniel Díaz Carrete and 1 more
Activity
benhillis commentedon Feb 6, 2017
This is on our backlog but is unlikely to make the Creators Update. I know we're planning on looking at this soon though.
For some context, I've looked at what causes this slowdown. For some reason stack has mapped an mind-bogglingly huge region of memory (I'm talking dozens of terabytes). When we fork we walk the entire address range to set up the new process's state. We have a design that should vastly speed this up, but we're approaching "pencils down" date for Creators Update.
ezrosent commentedon Feb 6, 2017
Gotcha, thanks for the context!
therealkenc commentedon Feb 6, 2017
Terabytes. That's awesome. Can't wait to see it in Resource Monitor.
benhillis commentedon Feb 6, 2017
I assume they're doing it to manage their own heap. It's a big "MAP_NORESERVE" region which Linux seems to intelligently handle since "allocate all the things" seems to be a common paradigm.
therealkenc commentedon Feb 7, 2017
This seems to be the related discussion over at ghc ticket 9706 here, for what it is worth. Quoth:
So by my math that's 100×1012×104 = 1018 ≅ 260, which gets you in just under the wire. Or something.
benhillis commentedon Feb 7, 2017
Adding Stephen Hufnagel (@stehufntdev) because he's been looking into this as well.
mckennapsean commentedon Feb 18, 2017
I have encountered a similar bug with plain
ghcandpandoc. Really slow just to call and print out version info. Can confirm for slow-ring Insider Build & the Windows Preview v.15.15014 (using the free VM).I found this slowdown by installing ghc v.8.0.2 (anything v.7.10 and below was fast) or by installing pandoc v.1.18 & above. See directions to install ghc or install pandoc for testing. If needed, I can provide a simple set of commands to reproduce.
They both run similarly slow/delayed for me on both systems, but I have not seen reports from other *nix users seeing similar slowdowns, so I am guessing this is WSL related.
sukhmel commentedon Feb 20, 2017
This does not require Stack to replicate, GHC compiler alone is enough. I'm experiencing the same dreadfully slow compiler work. Besides, programs compiled with 8.0.x are slow too.
wget http://downloads.haskell.org/~ghc/8.0.2/ghc-8.0.2-x86_64-deb8-linux.tar.xztar -xJf ghc-8.0.2-x86_64-deb8-linux.tar.xzcd ghc-8.0.2./configure --prefix=/tmp/ghcmake installtime /tmp/ghc/bin/ghc -e 'putStrLn ""'RyanGlScott commentedon Feb 20, 2017
Ben Hillis (@benhillis): I believe you've bumped into GHC 8.0's new block-structured heap for 64-bit platforms. From the GHC 8.0.1 release notes:
benhillis commentedon Feb 20, 2017
Ryan Scott (@RyanGlScott) - I suspect you are right. We need to modify the way our memory manager keeps track of uncommitted pages.
I'd be very curious to see some performance measurements on how much better their allocator performs versus raw mmap / munmap calls.
therealkenc commentedon Feb 20, 2017
I was going to quip that curiosity too, but stuck with "awesome" instead. So you benchmark 8.0 and find out it is some percent faster than 7.0. Or just as fast, but simpler. But you end up demonstrating not much in the exercise. The Haskell guys seem okay with a hello world app asking for a terabyte of virtual memory. The Chakra guys seem okay with asking for 32GB to print hello, and if you are going to do that, [expletive], why not ask for a TB. I am still academically interested in how they arrived at 32GB. Why not 64GB or 128GB? Certainly not because "that would be crazy".
It's working code. Smart people thought it was a good idea. Shrug. What you gonna do except sigh and re-work the memory manager.
RyanGlScott commentedon Feb 20, 2017
FWIW, Golang also does something similar by reserving a contiguous chunk of 512 GB of memory (see this comment).
I'm certainly not qualified enough to say how they came up with that number, other than that it's a power of two and—to use their words—"512 GB (MaxMem) should be big enough for now".
pechersky commentedon Apr 19, 2017
I have a workaround in the meantime, based on the discussion in https://ghc.haskell.org/trac/ghc/ticket/13304. It involves compiling your own GHC which does not utilize the large address space allocation, and then using that as the GHC for your stack builds. My workaround relies on then supplying that GHC as the common GHC for your projects. In my example, I will recompile GHC 8.0.2 using whatever ghc you already have on your system. I will also make sure that Cabal is installed using this GHC -- otherwise, installing other packages will fall under the same problem of slowness. I suggest cleaning your
~/.stackand other stack directories to make sure you don't have any GHC lying around with the large-allocation functionality.To fix, in the bash environment, I ran
Now you can do your
stack installandstack buildin your projects, using the specially compiled GHC.You can monitor the VIRT usage with something like
toporhtop. Trystack exec ghciand monitor VIRT before and after.sgraf812 commentedon Apr 21, 2017
Don't you also have to recompile
stackfor this?29 remaining items
therealkenc commentedon Aug 1, 2017
I have anecdotally found the same problem with
tar, which is (I think) separate from the huge memory allocation slowness. When I untar a large tarball (let's say 10GB) in a Linux VM, it returns almost immediately, because I have 20GB of RAM assigned to the VM and it all ends up in cache at nearmemcpy()speed. With WSL it seems to rate limit on writes to disk. I did not report it because I don't untar large files that often, and limiting on writes to disk is hard to prove these days without low level instrumentation (ugh, effort). But from the blinkenlights it looks like that is what's happening. It doesn't seem to be a CPU limiting thing, because of inefficientstat()calls per thegitslowness complaints, say.[edit] Another data point is
syncnever seems to do anything in WSL. With the same 10GB untar in a VM,synctakes countable time to flush the cache.jstarks commentedon Dec 19, 2017
We have improved mmap performance further in insider build 17063. I believe this makes stack ghc bearable to use now :).
AaronFriel commentedon Dec 20, 2017
Thank you! I can attest to the significant improvement.
cemerick commentedon Jan 23, 2018
Another anecdote: I opted into 17074 hoping to get acceptable working conditions, but
stack setuptook exactly an hour to complete (even with windows defender temporarily disabled). For comparison,stack setupundercmd.exestarting from scratch took ~4 minutes. I'll give working with the result a shot, but it doesn't look promising.Sorry for the negative report; keep doing great work, you'll get there. ❤️
hvr commentedon Feb 14, 2018
In the hopes this may be useful to somebody here: I've set up a GHC PPA optimised for WSL (i.e. built with
--disable-large-address-space) over athttps://launchpad.net/~hvr/+archive/ubuntu/ghc-wsl
It should merely be a matter of
and then simply prepending
/opt/ghc/bin/to your$PATHenv-var.cboudereau commentedon Apr 12, 2018
I would like to use VSCode on Windows + WSL + Stack ghci but due to this problem, it is really slow.
I will check if recompiling a custom ghc without large address space allocation is better or not. Thanks Yakov Pechersky (@pechersky) !
therealkenc commentedon May 24, 2018
nb: GHC is "still slow" (as it were) but this was deemed fixedininsiderbuilds back in July 2017, and finally made its way into the April Update.
windows.md: Delete outdated notes