Skip to content

Commit c0bb73e

Browse files
author
Johan Tibell
committed
developer guide: document performance considerations
1 parent eedee50 commit c0bb73e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ performance critical use, both in terms of large data quantities and high speed.
66
The declared cost of each operation is either worst-case or amortized, but
77
remains valid even if structures are shared.
88

9-
For developer and contributor documentation see docs/developer-guide.md.
9+
For developer and contributor documentation see the
10+
[Developer Guide](docs/developer-guide.md).

docs/developer-guide.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,24 @@ updating the spine of the tree).
111111
indexing, faster copying on modification (given that its size is statically
112112
know), and lower memory use.
113113

114-
## Strictness
115-
116-
Everything is strict. Laziness is the enemy of predictable performance.
114+
## Why things are fast
115+
116+
Performance is largely dominated by memory layout and allocation. The code has
117+
been carefully tuned by looking at the GHC core output and sometimes the
118+
assembly output. In particular there's no unnecessary allocation in the most
119+
important functions and the memory layout is about as good as we can get using
120+
GHC.
121+
122+
Avoiding allocation is done by making things strict (laziness is the enemy of
123+
predictable performance) and using `INLINABLE` to allow to be specialized at the
124+
call site (so key and value arguments to functions are passed as values rather
125+
than pointers to heap objects).
126+
127+
The main remaining bottlenecks are due to e.g. GHC not allowing us to unpack an
128+
array into a constructor. Two examples: the `Full` constructor is a separate
129+
heap object from the array it contains and the `Leaf` constructor contains
130+
pointers to the key and value instead of unpacking them into the
131+
constructor. There's nothing we can do about this at the moment.
117132

118133
## Backwards compatibility policy
119134

0 commit comments

Comments
 (0)