From 6860ce4912c9d9d2f641f4532106ee6a3412523d Mon Sep 17 00:00:00 2001 From: Alex Kudentsov <43482574+alexk37@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:36:47 +0700 Subject: cstore: T9376: list tag values only when there is a tag limit to check add_tag() read every existing value of the tag node, through the session's unionfs, each time it added one, although the list is used for nothing but the tag limit, and most tag nodes have none. Adding n values was therefore O(n^2): on a 1.5.1 VM the boot-time load of a config with a 10,000-rule prefix-list took 50 min 13 s (with the T9374 parser fix installed), and `load` of a 4,000-rule list 474 s. List the values only when tlimit > 0, the only case that uses them. With this change the same boot-time load took 37.4 s and the 4,000-rule `load` 16.3 s. --- src/cstore/cstore.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/cstore/cstore.cpp') diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp index bc6aa4d..c4a3579 100644 --- a/src/cstore/cstore.cpp +++ b/src/cstore/cstore.cpp @@ -2925,8 +2925,13 @@ Cstore::add_tag(unsigned int tlimit) string t; pop_cfg_path(t); vector cnodes; - // get child nodes, excluding deactivated ones. - get_all_child_node_names(cnodes, false, false); + /* get child nodes, excluding deactivated ones, only when there is a limit + * to check: listing them for every added value made adding n values to a + * tag node O(n^2) (loading a 10,000-entry prefix-list took 50 minutes). + */ + if (tlimit > 0) { + get_all_child_node_names(cnodes, false, false); + } bool ret = false; do { if (tlimit > 0 && tlimit <= cnodes.size()) { -- cgit v1.2.3