From 4ba379792397297fd7623af056c60264db613626 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 23:10:34 +0930 Subject: [PATCH] plugins/pay: iterate the htable properly, not from start each time. time lightning-cli -R --network=regtest --lightning-dir /tmp/ltests-k8jhvtty/test_pay_stress_1/lightning-1/ listpays > /dev/null Before: real 0m12.447s user 0m0.143s sys 0m0.008s After: real 0m2.054s user 0m0.114s sys 0m0.024s Signed-off-by: Rusty Russell --- plugins/pay.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/pay.c b/plugins/pay.c index 37c6f42d8..149cf65be 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1858,10 +1858,11 @@ static struct command_result *listsendpays_done(struct command *cmd, } } - /* Now we've collapsed them, provide summary (free mem as we go). */ - while ((pm = pay_map_first(&pay_map, &it)) != NULL) { + /* Now we've collapsed them, provide summary. */ + for (pm = pay_map_first(&pay_map, &it); + pm; + pm = pay_map_next(&pay_map, &it)) { add_new_entry(ret, buf, pm); - pay_map_del(&pay_map, pm); } pay_map_clear(&pay_map);