When I try gpg -K with my keyring (8744 keys), I found it costs 2.4s to query, but if I query my name, it only costs 0.2s. As keyboxd uses sqlite as the backend, it should have a similar performance. So I checked the source code. And then I found GnuPG never used the SQL query directly when gpg -K. It queries an OpenPGP key and uses the NEXT command to query the next key until it reaches the end. So GnuPG isn't querying, but is, instead, traversing.