1 |
Dnia June 27, 2020 6:34:13 AM UTC, Chun-Yu Shei <cshei@××××××.com> napisał(a): |
2 |
>According to cProfile, catpkgsplit is called up to 1-5.5 million times |
3 |
>during "emerge -uDvpU --with-bdeps=y @world". Adding a dict to cache |
4 |
>its |
5 |
>results reduces the time for this command from 43.53 -> 41.53 seconds |
6 |
>-- |
7 |
>a 4.8% speedup. |
8 |
|
9 |
|
10 |
Not saying caching is wrong for an interim solution but this is the kind of function where refactoring may yield even more gain. |
11 |
|
12 |
|
13 |
>--- |
14 |
> lib/portage/versions.py | 7 +++++++ |
15 |
> 1 file changed, 7 insertions(+) |
16 |
> |
17 |
>diff --git a/lib/portage/versions.py b/lib/portage/versions.py |
18 |
>index 0c21373cc..ffec316ce 100644 |
19 |
>--- a/lib/portage/versions.py |
20 |
>+++ b/lib/portage/versions.py |
21 |
>@@ -312,6 +312,7 @@ def _pkgsplit(mypkg, eapi=None): |
22 |
> |
23 |
> _cat_re = re.compile('^%s$' % _cat, re.UNICODE) |
24 |
> _missing_cat = 'null' |
25 |
>+_catpkgsplit_cache = {} |
26 |
> |
27 |
> def catpkgsplit(mydata, silent=1, eapi=None): |
28 |
> """ |
29 |
>@@ -331,6 +332,11 @@ def catpkgsplit(mydata, silent=1, eapi=None): |
30 |
> return mydata.cpv_split |
31 |
> except AttributeError: |
32 |
> pass |
33 |
>+ |
34 |
>+ cache_entry = _catpkgsplit_cache.get(mydata) |
35 |
>+ if cache_entry is not None: |
36 |
>+ return cache_entry |
37 |
>+ |
38 |
> mysplit = mydata.split('/', 1) |
39 |
> p_split = None |
40 |
> if len(mysplit) == 1: |
41 |
>@@ -343,6 +349,7 @@ def catpkgsplit(mydata, silent=1, eapi=None): |
42 |
> if not p_split: |
43 |
> return None |
44 |
> retval = (cat, p_split[0], p_split[1], p_split[2]) |
45 |
>+ _catpkgsplit_cache[mydata] = retval |
46 |
> return retval |
47 |
> |
48 |
> class _pkg_str(_unicode): |
49 |
|
50 |
|
51 |
-- |
52 |
Best regards, |
53 |
Michał Górny |