commit: a30cc858dd457c0db2539498dfd68c5d43e8a998
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 24 17:56:38 2026 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan 24 17:56:38 2026 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a30cc858
libq/tree: add note about choice made for foreach_pkg_gtree
document why we retrieve all metadata for all pkgs on the first
traversal
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/libq/tree.c b/libq/tree.c
index 2990cec..85e6c20 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -2284,7 +2284,24 @@ int tree_foreach_pkg
#ifdef ENABLE_GTREE
/* we don't optimise anything because reading a single file is fast
* enough, it just takes some memory, but any retrieval afterwards
- * comes straight from cache */
+ * comes straight from cache
+ * gtree is designed to be efficient when doing dependency
+ * resolution, e.g. many lookups for atoms and their metadata
+ * when you have to read the gtree twice, any benefit of skipping
+ * reading metadata or pkgs is undone, some numbers to illustrate
+ * this:
+ * - reading the full tree creating all pkgs + metadata: 0.77s
+ * - reading the full tree creating all pkgs no meta: 0.46s
+ * - reading the full tree creating only categories: 0.33s
+ * - reading the full tree creating nothing (a scan) 0.30s
+ * from this we can see that reading no metadata is 0.30s faster,
+ * but retrieving one package's metadata would take at least 0.30s
+ * since we don't know when we'd need metadata and when not, we
+ * basically take the worst case, for it is fastest when > 1 pkg is
+ * looked up
+ * note that the above is from a VM with bad/slow IO, running the
+ * same on a reasonable laptop, spends only 0.14s, so the perceived
+ * slowness is virtually absent in that case */
if (tree_foreach_pkg_gtree(tree) != 0)
return 1;
return tree_foreach_pkg(tree, callback, priv, sorted, query);