on b8178cd help sign in
streamly/docs/Build.md
61 lines 2.4 kB history raw
1# Compilation Options
3Recommended GHC options are:
5 `-O2 -fspec-constr-recursive=16 -fmax-worker-args=16`
7`-fspec-constr-recursive` is needed for better stream fusion by enabling
8the `SpecConstr` optimization in more cases.
10`-fmax-worker-args` is needed for better stream fusion by enabling the
11`SpecConstr` optimization in some important cases.
13In some cases, you may need to use `-funfolding-use-threshold` to make sure
14that the combinators fuse. The default value of this option is `60`. Increasing
15this default value can be detrimental in general, therefore, increase only if
16you suspect an issue. Hopefully GHC will fix this so that it is not needed in
17future. Some known examples:
19* use a value of `75` to fuse `S.chunksOf n (A.writeN n)`.
20* use a value of `150` to fully fuse `S.splitSuffixOn`.
22At the very least `-O` compilation option is required. In some cases, the
23program may exhibit memory hog with default optimization options. For example,
24the following program, if compiled without an optimization option, is known to
25hog memory:
27```
28main = S.drain $ S.concatMap S.fromList $ S.repeat []
29```
31# Multi-core Parallelism
33Concurrency without a threaded runtime may be a bit more efficient. Do not use
34threaded runtime unless you really need multi-core parallelism. To get
35multi-core parallelism use the following GHC options:
37 `-threaded -with-rtsopts "-N"`
39# Compiler Versions
41GHC 8.8.x seems to have a GC issue which causes space leak in concurrent
42streams especially when used with `-N` RTS option. The root cause of
43this has not yet been established. The leak is not seen with earlier
44versions of GHC.
46GHC 8.2.2 may hog memory and hang when building certain application using
47streamly (particularly the benchmark programs in the streamly package).
48Therefore we recommend avoiding using the GHC version 8.2.x.
50# Performance Optimizations
52If performance is below expectations:
54* Look for inlining functions in the fast path
55* Strictness annotations on data, specially the data used as accumulator in
56 folds and scans, can help in improving performance.
57* Strictness annotations on function arguments can help the compiler unbox
58 constructors in certain cases, improving performance.
59* Sometimes using `-XStrict` extension can help improve performance, if so you
60 may be missing some strictness annotations.
61* Use tail recursion for streaming data or for large loops