Blame SOURCES/0024-JSON-Improve-performance-of-json_events_cb.patch

3e48d9
From 58d8baa70172bb9862276ac5f542248c88d3faf4 Mon Sep 17 00:00:00 2001
3e48d9
From: Phil Sutter <psutter@redhat.com>
3e48d9
Date: Wed, 24 Jun 2020 18:48:14 +0200
3e48d9
Subject: [PATCH] JSON: Improve performance of json_events_cb()
3e48d9
3e48d9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1835300
3e48d9
Upstream Status: nftables commit c96c7da272e33
3e48d9
3e48d9
commit c96c7da272e33a34770c4de4e3e50f7ed264672e
3e48d9
Author: Phil Sutter <phil@nwl.cc>
3e48d9
Date:   Wed May 13 16:29:51 2020 +0200
3e48d9
3e48d9
    JSON: Improve performance of json_events_cb()
3e48d9
3e48d9
    The function tries to insert handles into JSON input for echo option.
3e48d9
    Yet there may be nothing to do if the given netlink message doesn't
3e48d9
    contain a handle, e.g. if it is an 'add element' command. Calling
3e48d9
    seqnum_to_json() is pointless overhead in that case, and if input is
3e48d9
    large this overhead is significant. Better wait with that call until
3e48d9
    after checking if the message is relevant at all.
3e48d9
3e48d9
    Signed-off-by: Phil Sutter <phil@nwl.cc>
3e48d9
    Acked-by: Eric Garver <eric@garver.life>
3e48d9
---
3e48d9
 src/parser_json.c | 9 ++++++---
3e48d9
 1 file changed, 6 insertions(+), 3 deletions(-)
3e48d9
3e48d9
diff --git a/src/parser_json.c b/src/parser_json.c
3e48d9
index c48faa8..ce8e566 100644
3e48d9
--- a/src/parser_json.c
3e48d9
+++ b/src/parser_json.c
3e48d9
@@ -3845,12 +3845,15 @@ static uint64_t handle_from_nlmsg(const struct nlmsghdr *nlh)
3e48d9
 }
3e48d9
 int json_events_cb(const struct nlmsghdr *nlh, struct netlink_mon_handler *monh)
3e48d9
 {
3e48d9
-	json_t *tmp, *json = seqnum_to_json(nlh->nlmsg_seq);
3e48d9
 	uint64_t handle = handle_from_nlmsg(nlh);
3e48d9
+	json_t *tmp, *json;
3e48d9
 	void *iter;
3e48d9
 
3e48d9
-	/* might be anonymous set, ignore message */
3e48d9
-	if (!json || !handle)
3e48d9
+	if (!handle)
3e48d9
+		return MNL_CB_OK;
3e48d9
+
3e48d9
+	json = seqnum_to_json(nlh->nlmsg_seq);
3e48d9
+	if (!json)
3e48d9
 		return MNL_CB_OK;
3e48d9
 
3e48d9
 	tmp = json_object_get(json, "add");
3e48d9
-- 
252916
2.31.1
3e48d9