From 8adaac7f295a2d42bf1a16c712d51b413e16e61a Mon Sep 17 00:00:00 2001 From: Armaan Sandhu Date: Fri, 4 Sep 2026 13:40:47 -0400 Subject: [PATCH] logs-show: pre-size the per-entry JSON field hashmap journal_entry_to_json() builds a fresh hashmap for every entry and then fills it with that entry's fields, of which there are typically around twenty. Since the hashmap starts out empty it has to grow several times per entry, and every growth rehashes everything inserted so far. journalctl -o json spent about a quarter of its time in siphash, a third of that under resize_buckets(). Reserve room up front. On a 730M journal spread over 100 files, journalctl -o json -n 200000 goes from 5.71s to 4.64s. --- src/shared/logs-show.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 513d76558e..ce41d2d87a 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1254,6 +1254,12 @@ int journal_entry_to_json( if (!h) return log_oom(); + /* A typical entry has around twenty fields and this hashmap is built fresh for each one, so + * size it up front rather than rehashing repeatedly while filling it. */ + r = hashmap_reserve(h, 32); + if (r < 0) + return log_oom(); + r = update_json_data(h, flags, "__CURSOR", cursor, SIZE_MAX); if (r < 0) return r;