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.
This commit is contained in:
committed by
Yu Watanabe
parent
79e32e7c73
commit
8adaac7f29
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user