Commit a3ee2d9
committed
Ensure that transaction tokens are unique in the mempool benchmarks
Data of type `Token` is what a mempool `TestBlock` transaction (`Tx`) consumes
and produces. Previously, this token was a newtype around a `Word8`. T there can
only be around 256 unqiue tokens, which means that its likely for this value to
wrap around. In the current benchmark scenario, where we add linearly dependent
transactions with only one input and output to a mempool, this wrap around was
occurring and therefore the list of transaction that was being generated had
many duplicates. The type of tokens is therefore changed to be a newtype around
an `Int`, which won't wrap around.
Abovementioned change exposed subtle performance effects of this wrap-around.
Most of this can be attributed to the `Tx` type doubling as a `GenTxId`. The
mempool keeps track of these identifiers in a set. Since there were only around
256 unique transactions, this set was rather small. Changing tokens to be `Int`s
ensured that this set could grow rather large, and that by itself has effects on.
Apart from change the type of tokens, the mempool benchmark setup is reworked:
* Transactions that are used as benchmark inputs are pre-generated and fully
evaluated so that the generation work is not measured in the benchmarked
function itself.
* Instead of opening a mempool once and removing transactions after each
benchmark run, a new mempool is opened in each benchmark run. Removing
transactions proved to be prohibitively costly compared to the cost of opening
a new mempool.
* A new benchmark is added that measures just the mempool setup time. To obtain
the cost of just adding the transactions without cost of opening the mempool,
the time of this new benchmark can be manually subtracted from the full
benchmark time.1 parent 7bed57f commit a3ee2d9
File tree
2 files changed
+19
-16
lines changed- ouroboros-consensus/bench/mempool-bench
- Bench/Consensus/Mempool
2 files changed
+19
-16
lines changedLines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
| 58 | + | |
58 | 59 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 60 | + | |
65 | 61 | | |
66 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | | - | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
0 commit comments