[PackageKit/f15] backport "python: Speed up get_package_list()" from 0.6.22 (#748790)

Kevin Kofler kkofler at fedoraproject.org
Mon Apr 23 15:47:36 UTC 2012


commit 985c354c9fd001d3942397fff183f07d07837dff
Author: Kevin Kofler <Kevin at tigcc.ticalc.org>
Date:   Mon Apr 23 17:47:22 2012 +0200

    backport "python: Speed up get_package_list()" from 0.6.22 (#748790)
    
    * Mon Apr 23 2012 Kevin Kofler  <Kevin at tigcc.ticalc.org> - 0.6.17-2
    - backport "python: Speed up get_package_list()" from 0.6.22 (#748790)

 ...t-0.6.17-python-Speed-up-get_package_list.patch |   59 ++++++++++++++++++++
 PackageKit.spec                                    |   10 +++-
 2 files changed, 68 insertions(+), 1 deletions(-)
---
diff --git a/PackageKit-0.6.17-python-Speed-up-get_package_list.patch b/PackageKit-0.6.17-python-Speed-up-get_package_list.patch
new file mode 100644
index 0000000..83af7b7
--- /dev/null
+++ b/PackageKit-0.6.17-python-Speed-up-get_package_list.patch
@@ -0,0 +1,59 @@
+From ca620312b627a2831e6c3e9f60126233a0f137e8 Mon Sep 17 00:00:00 2001
+Message-Id: <ca620312b627a2831e6c3e9f60126233a0f137e8.1335195691.git.kevin.kofler at chello.at>
+From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Trnka?= <tomastrnka at gmx.com>
+Date: Wed, 4 Apr 2012 12:17:45 +0100
+Subject: [PATCH] python: Speed up get_package_list()
+
+This patch replaces the quadratic monstrosity with an approximately linear
+equivalent.
+
+On my system (40297 installed+available packages) this gets the time spent in
+get_package_list to 1.3 s from the initial ~600 s. In other words, pkcon
+refresh now spends just about 20 s CPU time instead of 8 minutes.
+
+Signed-off-by: Richard Hughes <richard at hughsie.com>
+---
+ lib/python/packagekit/filter.py |   13 +++++++++----
+ 1 files changed, 9 insertions(+), 4 deletions(-)
+
+diff --git a/lib/python/packagekit/filter.py b/lib/python/packagekit/filter.py
+index 0eedd15..d66f630 100644
+--- a/lib/python/packagekit/filter.py
++++ b/lib/python/packagekit/filter.py
+@@ -21,6 +21,7 @@
+ # imports
+ from enums import *
+ from package import PackagekitPackage
++import collections
+ 
+ class PackagekitFilter(object, PackagekitPackage):
+ 
+@@ -83,17 +84,21 @@ class PackagekitFilter(object, PackagekitPackage):
+             if self._filter_base(pkg):
+                 self.package_list.append((pkg, state))
+ 
++        # prepare lookup table of installed packages
++        installed_dict = collections.defaultdict(list)
++        for pkg, state in self.package_list:
++            if state is INFO_INSTALLED:
++                installed_dict[self._pkg_get_name(pkg)].append(pkg)
++
+         # check there are not available versions in the package list
+         # that are older than the installed version
+         package_list = self.package_list
+         self.package_list = []
+         for pkg, state in package_list:
+ 
+-            add = True;
++            add = True
+             if state is INFO_AVAILABLE:
+-                for pkg_tmp, state_tmp in self.package_list:
+-                    if state_tmp is not INFO_INSTALLED:
+-                        continue
++                for pkg_tmp in installed_dict[self._pkg_get_name(pkg)]:
+                     rc = self._pkg_compare(pkg, pkg_tmp)
+ 
+                     # don't add if the same as the installed package
+-- 
+1.7.6.5
+
diff --git a/PackageKit.spec b/PackageKit.spec
index e3ea3c0..a7c9294 100644
--- a/PackageKit.spec
+++ b/PackageKit.spec
@@ -3,7 +3,7 @@
 Summary:   Package management service
 Name:      PackageKit
 Version:   0.6.17
-Release:   1%{?dist}
+Release:   2%{?dist}
 License:   GPLv2+ and LGPLv2+
 URL:       http://www.packagekit.org
 Source0:   http://www.packagekit.org/releases/%{name}-%{version}.tar.xz
@@ -14,6 +14,10 @@ Patch0:    PackageKit-0.3.8-Fedora-Vendor.conf.patch
 # Fedora specific: the yum backend doesn't do time estimation correctly
 Patch1:    PackageKit-0.4.4-Fedora-turn-off-time.conf.patch
 
+## upstream patches
+# backport "python: Speed up get_package_list()" from 0.6.22 (#748790)
+Patch100:  PackageKit-0.6.17-python-Speed-up-get_package_list.patch
+
 Requires: PackageKit-glib = %{version}-%{release}
 Requires: PackageKit-backend
 Requires: shared-mime-info
@@ -250,6 +254,7 @@ user to restart the computer or remove and re-insert the device.
 %setup -q
 %patch0 -p1 -b .fedora
 %patch1 -p1 -b .no-time
+%patch100 -p1 -b .python-speedup
 
 %build
 %configure \
@@ -464,6 +469,9 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
 %{_includedir}/PackageKit/backend/*.h
 
 %changelog
+* Mon Apr 23 2012 Kevin Kofler  <Kevin at tigcc.ticalc.org> - 0.6.17-2
+- backport "python: Speed up get_package_list()" from 0.6.22 (#748790)
+
 * Mon Aug 01 2011 Richard Hughes  <rhughes at redhat.com> - 0.6.17-1
 - New upstream release.
 - Manually convert the results of GetDetails to unicode.


More information about the scm-commits mailing list