lightningd: use hash map for peers instead of linked list.

After connecting 100,000 peers with one channel each (not all at
once!), we see various places where we exhibit O(N^2) behaviour.

Fix these by keeping a map of id->peer instead of a simple
linked-list.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-18 15:34:32 +10:30
committed by Alex Myers
parent 17aa047b17
commit cfa632b0e9
11 changed files with 143 additions and 51 deletions

View File

@@ -3,6 +3,7 @@
#include "config.h"
#include <lightningd/htlc_end.h>
#include <lightningd/htlc_set.h>
#include <lightningd/peer_control.h>
#include <signal.h>
#include <sys/stat.h>
#include <wallet/wallet.h>
@@ -178,8 +179,8 @@ struct lightningd {
/* Daemon looking after peers during init / before channel. */
struct subd *connectd;
/* All peers we're tracking. */
struct list_head peers;
/* All peers we're tracking (by node_id) */
struct peer_node_id_map *peers;
/* Outstanding connect commands. */
struct list_head connects;