From 5e1bbb08c7c059274e3ab7f4da56f5fb7231f274 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 12 Feb 2026 09:12:10 +1030 Subject: [PATCH] gossmap: reduce load times by 20% It's actually quite quick to load a cache-hot 308,874,377 byte gossip_store (normal -Og build), but perf does show time spent in siphash(), which is a bit overkill here, so drop that: Before: Time to load: 66718983-78037766(7.00553e+07+/-2.8e+06)nsec After: Time to load: 54510433-57991725(5.61457e+07+/-1e+06)nsec We could save maybe 10% more by disabling checksums, but having that assurance is nice. Signed-off-by: Rusty Russell --- common/gossmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/gossmap.c b/common/gossmap.c index 9d52569d5..744890bba 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -29,11 +29,7 @@ static bool chanidx_eq_id(const ptrint_t *pidx, struct short_channel_id pidxid = chanidx_id(pidx); return short_channel_id_eq(pidxid, scid); } -static size_t scid_hash(const struct short_channel_id scid) -{ - return siphash24(siphash_seed(), &scid, sizeof(scid)); -} -HTABLE_DEFINE_NODUPS_TYPE(ptrint_t, chanidx_id, scid_hash, chanidx_eq_id, +HTABLE_DEFINE_NODUPS_TYPE(ptrint_t, chanidx_id, short_channel_id_hash, chanidx_eq_id, chanidx_htable); static struct node_id nodeidx_id(const ptrint_t *pidx); @@ -42,9 +38,16 @@ static bool nodeidx_eq_id(const ptrint_t *pidx, const struct node_id id) struct node_id pidxid = nodeidx_id(pidx); return node_id_eq(&pidxid, &id); } +/* You need to spend sats to create a channel to advertize your nodeid, + * so creating clashes is not free: we can be lazy! */ static size_t nodeid_hash(const struct node_id id) { - return siphash24(siphash_seed(), &id, PUBKEY_CMPR_LEN); + size_t val; + size_t off = siphash_seed()->u.u8[0] % 16; + + BUILD_ASSERT(15 + sizeof(val) < sizeof(id.k)); + memcpy(&val, id.k + off, sizeof(val)); + return val; } HTABLE_DEFINE_NODUPS_TYPE(ptrint_t, nodeidx_id, nodeid_hash, nodeidx_eq_id, nodeidx_htable);