Reputation: 6392
When creating a new Stack project, the executable gets the following ghc-options
- -threaded
- -rtsopts
- -with-rtsopts=-N
Looking at the man ghc
, I found the following:
-threaded
Use the threaded runtime
-rtsopts[=⟨none|some|all⟩]
Control whether the RTS behaviour can be tweaked via command-lineflags and the GHCRTS environment variable. Using none means no RTS
flags can be given; some means only a minimum of safe options can be given (the default), and all (or no argument at all) means
that all RTS flags are permitted.
-with-rtsopts=⟨opts⟩
Set the default RTS options to ⟨opts⟩.
This hardly tells me anything. Does the threaded runtime refer to the runtime of the compiler or a runtime of the resulting executable? What are these rtsopts for? Are these options somehow beneficial? If yes, why are they not the default? Why does the executable get them and the library code not:
library:
source-dirs: src
# notice no ghc-options field here!
Upvotes: 3
Views: 328
Reputation: 120711
It refers to the runtime of the resulting executable. These options allow the final program to run multithreaded, i.e. to exploit parallel or concurrent execution on a multicore machine. This is mostly benefitial for performance, and particularly for responsiveness of interactive applications (some are virtually or literally unusable when not run with the threaded runtime).
The runtime is always only linked to an executable; you may think of it as similar to the Java virtual machine that executes a bytecode program, except the Haskell runtime is much more stripped down and doesn't need to do actually do much code interpreting, it mostly just handles the memory requirements and assigns Haskell threads to OS threads.
It is thus not linked to libraries, except at the very end when you use the library in an executable. That's why the option doesn't appear in the library
section. (Although, it would actually be quite handy if libraries had a way to indicate “when you use this in an exectuable, it should be linked with the threaded runtime”, but this would have ramifications and I don't think there is anything that allows something like this.)
Upvotes: 6