Commit 63fa918
committed
Properly pre-allocate
When we build a new `NetworkGraph` from empty, we're generally
doing an initial startup and will be syncing the graph very soon.
Using an initially-empty `IndexedMap` for the `channels` and
`nodes` results in quite some memory churn, with the initial RGS
application benchmark showing 15% of its time in pagefault handling
alone (i.e. allocating new memory from the OS, let alone the 23%
of time in `memmove`).
Further, when deserializing a `NetworkGraph`, we'd swapped the
expected node and channel count constants, leaving the node map
too small and causing map doubling as we read entries from disk.
Finally, when deserializing, allocating only exactly the amount of
map entries we need is likely to lead to at least one doubling, so
we're better off just over-estimating the number of nodes and
channels and allocating what we want.
Here we just always allocate `channels` and `nodes` based on
constants, leading to a 20%-ish speedup in the initial RGS
application benchmark.NetworkGraph channel/node maps1 parent 8eb3bd7 commit 63fa918
1 file changed
+13
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1660 | 1660 | | |
1661 | 1661 | | |
1662 | 1662 | | |
1663 | | - | |
1664 | | - | |
| 1663 | + | |
1665 | 1664 | | |
1666 | 1665 | | |
1667 | 1666 | | |
| |||
1673 | 1672 | | |
1674 | 1673 | | |
1675 | 1674 | | |
1676 | | - | |
1677 | | - | |
| 1675 | + | |
1678 | 1676 | | |
1679 | 1677 | | |
1680 | 1678 | | |
| |||
1750 | 1748 | | |
1751 | 1749 | | |
1752 | 1750 | | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1753 | 1760 | | |
1754 | 1761 | | |
1755 | 1762 | | |
| |||
1760 | 1767 | | |
1761 | 1768 | | |
1762 | 1769 | | |
1763 | | - | |
1764 | | - | |
| 1770 | + | |
| 1771 | + | |
1765 | 1772 | | |
1766 | 1773 | | |
1767 | 1774 | | |
| |||
0 commit comments