#1133971 With 10+ apt_preferences(5) globs pinned, "apt show mg" is much slower than "apt-cache show mg"

Package:
apt
Source:
apt
Description:
commandline package manager
Submitter:
Trent W. Buck
Date:
2026-04-17 01:23:02 UTC
Severity:
normal
#1133971#5
Date:
2026-04-16 05:06:03 UTC
From:
To:
I noticed a significant slowdown as I add Package: globs to apt_preferences.
1 glob costs 0.5-0.8s
10 globs costs costs 2-3s
60 globs costs 8-10s
It does not matter if these globs match 10,000 packages or 0 packages.

Is this an expected amount of delay, or has something gone wrong?


I noticed that apt show & apt list still exhibit this slowdown, where
apt-cache show and dpkg-query --show do not.

Is the new CLI (/bin/apt) loading apt_preferences(5) when it does not need to?


Attached is a basic test set and its output.
I tested apt/trixie (3.0.3) and apt/forky (3.2.0), both against trixie's package data.
Both showed the same slowdown.


PS: I acknowledge the patterns in my tests indicate I'm doing weird/dumb things.
But I think there are probably legitimate reasons to have 10 globs?
Or... thinking about it more, I guess most use cases are either
"Package: *" (testing/unstable hybrids) or
"Package: foo" (apt-listbugs pinning a specific known-buggy package).
And neither of those are globs...  OK, yes,
pinning "Package: *" takes ~0.5s and
pinning "Package: * * *" takes ~2s and
pinning 62 specific packages (src:libreoffice, src:linux, clang-17, clang-18, &c) takes 0.4s.
pinning 13000 specific packages (each foo-dev by name) takes 0.4s.
So this slowdown hits ONLY when you have globs rather than exact package names.
Which is a MUCH less common thing to do.

#1133971#10
Date:
2026-04-16 05:35:29 UTC
From:
To:
Here's an simpler comparison showing the symptoms are definitely only
with glob/regex patterns, not literals.


root@hera:/# printf >/etc/apt/preferences  'Pin-Priority: -1\nPin:
version *\nPackage: %s\n' '*-dev *-devel *-dbg *-dbgsym *-prof *-src
*-source *-dkms *-debug *-compiler *-server *-test *-tests'; time
apt-cache policy | wc -l
14747
real    0m2.039s
user    0m1.962s
sys     0m0.087s


root@hera:/# printf >/etc/apt/preferences  'Pin-Priority: -1\nPin:
version *\nPackage: %s\n'
'/-(dev|devel|dbg|dbgsym|prof|src|source|dkms|debug|compiler|server|test|tests)$/';
time apt-cache policy | wc -l
14747
real    0m6.787s
user    0m6.764s
sys     0m0.026s


root@hera:/# printf >/etc/apt/preferences  'Pin-Priority: -1\nPin:
version *\nPackage: %s\n' "$(apt-cache pkgnames | grep -E -e
"-(dev|devel|dbg|dbgsym|prof|src|source|dkms|debug|compiler|server|test|tests)$"
| tr '\n' ' ')"; time apt-cache policy | wc -l
14747
real    0m0.176s
user    0m0.140s
sys     0m0.043s

#1133971#15
Date:
2026-04-16 17:52:07 UTC
From:
To:
it needs to; it shows pinning.
#1133971#20
Date:
2026-04-17 01:20:32 UTC
From:
To:
Fair enough.  I suspected this, but didn't work it out on my own.

Based on this &
my current understanding that
globs/regexps are slow, but
"Package: *" or "Package: exact-name" are fast,
I am OK with closing or wontfixing this ticket.