Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r10764 - main/trunk/pym/portage/dbapi
Date: Mon, 23 Jun 2008 10:00:19
Message-Id: E1KAiqL-0007dG-Op@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-06-23 10:00:12 +0000 (Mon, 23 Jun 2008)
3 New Revision: 10764
4
5 Modified:
6 main/trunk/pym/portage/dbapi/vartree.py
7 Log:
8 Bug #228977 - During dblink._preserve_libs() calls, cache results of
9 LinkageMap.findProviders(), LinkageMap.findConsumers(), and os.path.realpath()
10 calls in order to improve performance. This makes a huge difference in
11 performance for glibc upgrades since glibc provides so many libs to
12 check consumerge for.
13
14
15 Modified: main/trunk/pym/portage/dbapi/vartree.py
16 ===================================================================
17 --- main/trunk/pym/portage/dbapi/vartree.py 2008-06-23 02:40:38 UTC (rev 10763)
18 +++ main/trunk/pym/portage/dbapi/vartree.py 2008-06-23 10:00:12 UTC (rev 10764)
19 @@ -201,30 +201,48 @@
20 def findProviders(self, obj):
21 if not self._libs:
22 self.rebuild()
23 +
24 + realpath_cache = {}
25 + def realpath(p):
26 + real_path = realpath_cache.get(p)
27 + if real_path is None:
28 + real_path = os.path.realpath(p)
29 + realpath_cache[p] = real_path
30 + return real_path
31 +
32 rValue = {}
33 if obj not in self._obj_properties:
34 - obj = os.path.realpath(obj)
35 + obj = realpath(obj)
36 if obj not in self._obj_properties:
37 raise KeyError("%s not in object list" % obj)
38 arch, needed, path, soname = self._obj_properties[obj]
39 path.extend(self._defpath)
40 - path = [os.path.realpath(x) for x in path]
41 + path = set(realpath(x) for x in path)
42 for x in needed:
43 rValue[x] = set()
44 if x not in self._libs or arch not in self._libs[x]:
45 continue
46 for y in self._libs[x][arch]["providers"]:
47 - if x[0] == os.sep and os.path.realpath(x) == os.path.realpath(y):
48 + if x[0] == os.sep and realpath(x) == realpath(y):
49 rValue[x].add(y)
50 - elif os.path.realpath(os.path.dirname(y)) in path:
51 + elif realpath(os.path.dirname(y)) in path:
52 rValue[x].add(y)
53 return rValue
54
55 def findConsumers(self, obj):
56 if not self._libs:
57 self.rebuild()
58 +
59 + realpath_cache = {}
60 + def realpath(p):
61 + real_path = realpath_cache.get(p)
62 + if real_path is None:
63 + real_path = os.path.realpath(p)
64 + realpath_cache[p] = real_path
65 + return real_path
66 +
67 if obj not in self._obj_properties:
68 - obj = os.path.realpath(obj)
69 + obj = realpath(obj)
70 if obj not in self._obj_properties:
71 raise KeyError("%s not in object list" % obj)
72 rValue = set()
73 @@ -233,10 +251,10 @@
74 if obj in self._libs[soname][arch]["providers"]:
75 for x in self._libs[soname][arch]["consumers"]:
76 path = self._obj_properties[x][2]
77 - path = [os.path.realpath(y) for y in path+self._defpath]
78 - if soname[0] == os.sep and os.path.realpath(soname) == os.path.realpath(obj):
79 + path = [realpath(y) for y in path+self._defpath]
80 + if soname[0] == os.sep and realpath(soname) == realpath(obj):
81 rValue.add(x)
82 - elif os.path.realpath(os.path.dirname(obj)) in path:
83 + elif realpath(os.path.dirname(obj)) in path:
84 rValue.add(x)
85 return rValue
86
87 @@ -1995,9 +2013,15 @@
88 if os.path.islink(x) and os.path.realpath(x) in candidates and x not in mycontents:
89 candidates.add(x)
90
91 + provider_cache = {}
92 + consumer_cache = {}
93 +
94 # ignore any libs that are only internally used by the package
95 def has_external_consumers(lib, contents, otherlibs):
96 - consumers = linkmap.findConsumers(lib)
97 + consumers = consumer_cache.get(lib)
98 + if consumers is None:
99 + consumers = linkmap.findConsumers(lib)
100 + consumer_cache[lib] = consumers
101 contents_without_libs = [x for x in contents if x not in otherlibs]
102
103 # just used by objects that will be autocleaned
104 @@ -2024,10 +2048,19 @@
105 continue
106 # only preserve the lib if there is no other copy to use for each consumer
107 keep = False
108 - for c in linkmap.findConsumers(lib):
109 +
110 + lib_consumers = consumer_cache.get(lib)
111 + if lib_consumers is None:
112 + lib_consumers = linkmap.findConsumers(lib)
113 + consumer_cache[lib] = lib_consumers
114 +
115 + for c in lib_consumers:
116 localkeep = True
117 - providers = linkmap.findProviders(c)
118 -
119 + providers = provider_cache.get(c)
120 + if providers is None:
121 + providers = linkmap.findProviders(c)
122 + provider_cache[c] = providers
123 +
124 for soname in providers:
125 if lib in providers[soname]:
126 for p in providers[soname]:
127
128 --
129 gentoo-commits@l.g.o mailing list