Skip to content

packagekit: Avoid 600000 allocations when comparing package IDs

When refining apps, each app was found in a (long) list of results from packagekit by iterating over the list and comparing each pair of package IDs. Each comparison split the package IDs into components (using string operations) and compared each pair of components, ignoring the DATA component.

On my Fedora 32 system, that involved arrays of 200 and 700 results from packagekit, and 100 to 200 apps being refined. Each app had 1 or 2 source IDs to compare. That resulted in around 200000 calls to gs_pk_compare_ids().

To speed it all up, this commit copies the packagekit results into a hash table and introduces custom hash and equality functions to avoid heap allocations when comparing package IDs.

This reduces the time for the two parallel packagekit-refine operations on my machine at gnome-software startup from 0.5s/2.7s to 0.3s/2.2s (speedups of 40% and 18% respectively).

Signed-off-by: Philip Withnall withnall@endlessm.com

Merge request reports