on fa8a2cf help sign in
streamly/docs/Build.md
91 lines 2.9 kB history raw
1# Compilation Options
3## Recommended Options
5Benchmarks show that GHC 8.8 has significantly better performance than GHC 8.6
6in many cases.
8Use the following GHC options:
10```
11 -O2
12 -fdicts-strict
13 -fspec-constr-recursive=16
14 -fmax-worker-args=16
15```
17## Using Fusion Plugin
19In many cases `fusion-plugin` can improve performance by better stream
20fusion. However, in some cases performance may also regress. Please note
21that the `fusion-plugin` package works only for GHC >= 8.6.
23* Install the
24[fusion-plugin](https://hackage.haskell.org/package/fusion-plugin)
25package or add it to the `build-depends` section of your program in the
26cabal file.
28* Use the following GHC option in addition to the options listed in the
29 previous section:
31```
32 -fplugin=Fusion.Plugin
33```
35## Minimal
37At the very least `-O -fdicts-strict` compilation options are
38required. If these options are not used, the program may exhibit memory
39hog. For example, the following program, if compiled without an
40optimization option, is known to hog memory:
42```
43main = S.drain $ S.concatMap S.fromList $ S.repeat []
44```
46## Explanation
48* `-fdicts-strict` is needed to avoid [a GHC
49issue](https://gitlab.haskell.org/ghc/ghc/issues/17745) leading to
50memory leak in some cases.
52* `-fspec-constr-recursive` is needed for better stream fusion by enabling
53the `SpecConstr` optimization in more cases.
55* `-fmax-worker-args` is needed for better stream fusion by enabling the
56`SpecConstr` optimization in some important cases.
58* `-fplugin=Fusion.Plugin` enables predictable stream fusion
59optimization in certain cases by helping the compiler inline internal
60bindings and therefore enabling case-of-case optimization. In some
61cases, especially in some fileio benchmarks, it can make a difference of
625-10x better performance.
64# Multi-core Parallelism
66Concurrency without a threaded runtime may be a bit more efficient. Do not use
67threaded runtime unless you really need multi-core parallelism. To get
68multi-core parallelism use the following GHC options:
70 `-threaded -with-rtsopts "-N"`
72# Compiler Versions
74Use GHC 8.8 for best performance.
76GHC 8.2.2 may hog memory and hang when building certain application using
77streamly (particularly the benchmark programs in the streamly package).
78Therefore we recommend avoiding using the GHC version 8.2.x.
80# Performance Optimizations
82If performance is below expectations:
84* Look for inlining functions in the fast path
85* Strictness annotations on data, specially the data used as accumulator in
86 folds and scans, can help in improving performance.
87* Strictness annotations on function arguments can help the compiler unbox
88 constructors in certain cases, improving performance.
89* Sometimes using `-XStrict` extension can help improve performance, if so you
90 may be missing some strictness annotations.
91* Use tail recursion for streaming data or for large loops