on 202c33d help sign in
streamly/docs/Build.md
95 lines 3.1 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 -fmax-worker-args=16
14 -fspec-constr-recursive=16
15```
17Important Note: In certain cases it is possible that GHC takes too long to
18compile with `-fspec-constr-recursive=16`, if that happens please reduce the
19value or remove that option.
21## Using Fusion Plugin
23In many cases `fusion-plugin` can improve performance by better stream
24fusion. However, in some cases performance may also regress. Please note
25that the `fusion-plugin` package works only for GHC >= 8.6.
27* Install the
28[fusion-plugin](https://hackage.haskell.org/package/fusion-plugin)
29package or add it to the `build-depends` section of your program in the
30cabal file.
32* Use the following GHC option in addition to the options listed in the
33 previous section:
35```
36 -fplugin=Fusion.Plugin
37```
39## Minimal
41At the very least `-O -fdicts-strict` compilation options are
42required. If these options are not used, the program may exhibit memory
43hog. For example, the following program, if compiled without an
44optimization option, is known to hog memory:
46```
47main = S.drain $ S.concatMap S.fromList $ S.repeat []
48```
50## Explanation
52* `-fdicts-strict` is needed to avoid [a GHC
53issue](https://gitlab.haskell.org/ghc/ghc/issues/17745) leading to
54memory leak in some cases.
56* `-fspec-constr-recursive` is needed for better stream fusion by enabling
57the `SpecConstr` optimization in more cases.
59* `-fmax-worker-args` is needed for better stream fusion by enabling the
60`SpecConstr` optimization in some important cases.
62* `-fplugin=Fusion.Plugin` enables predictable stream fusion
63optimization in certain cases by helping the compiler inline internal
64bindings and therefore enabling case-of-case optimization. In some
65cases, especially in some fileio benchmarks, it can make a difference of
665-10x better performance.
68# Multi-core Parallelism
70Concurrency without a threaded runtime may be a bit more efficient. Do not use
71threaded runtime unless you really need multi-core parallelism. To get
72multi-core parallelism use the following GHC options:
74 `-threaded -with-rtsopts "-N"`
76# Compiler Versions
78Use GHC 8.8 for best performance.
80GHC 8.2.2 may hog memory and hang when building certain application using
81streamly (particularly the benchmark programs in the streamly package).
82Therefore we recommend avoiding using the GHC version 8.2.x.
84# Performance Optimizations
86If performance is below expectations:
88* Look for inlining functions in the fast path
89* Strictness annotations on data, specially the data used as accumulator in
90 folds and scans, can help in improving performance.
91* Strictness annotations on function arguments can help the compiler unbox
92 constructors in certain cases, improving performance.
93* Sometimes using `-XStrict` extension can help improve performance, if so you
94 may be missing some strictness annotations.
95* Use tail recursion for streaming data or for large loops