Gentoo Archives: gentoo-portage-dev

From: Chun-Yu Shei <cshei@××××××.com>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] Add caching to a few commonly used functions
Date: Sat, 27 Jun 2020 06:34:21
Message-Id: 20200627063415.936177-1-cshei@google.com
1 Hi,
2
3 I was recently interested in whether portage could be speed up, since
4 dependency resolution can sometimes take a while on slower machines.
5 After generating some flame graphs with cProfile and vmprof, I found 3
6 functions which seem to be called extremely frequently with the same
7 arguments: catpkgsplit, use_reduce, and match_from_list. In the first
8 two cases, it was simple to cache the results in dicts, while
9 match_from_list was a bit trickier, since it seems to be a requirement
10 that it return actual entries from the input "candidate_list". I also
11 ran into some test failures if I did the caching after the
12 mydep.unevaluated_atom.use and mydep.repo checks towards the end of the
13 function, so the caching is only done up to just before that point.
14
15 The catpkgsplit change seems to definitely be safe, and I'm pretty sure
16 the use_reduce one is too, since anything that could possibly change the
17 result is hashed. I'm a bit less certain about the match_from_list one,
18 although all tests are passing.
19
20 With all 3 patches together, "emerge -uDvpU --with-bdeps=y @world"
21 speeds up from 43.53 seconds to 30.96 sec -- a 40.6% speedup. "emerge
22 -ep @world" is just a tiny bit faster, going from 18.69 to 18.22 sec
23 (2.5% improvement). Since the upgrade case is far more common, this
24 would really help in daily use, and it shaves about 30 seconds off
25 the time you have to wait to get to the [Yes/No] prompt (from ~90s to
26 60s) on my old Sandy Bridge laptop when performing normal upgrades.
27
28 Hopefully, at least some of these patches can be incorporated, and please
29 let me know if any changes are necessary.
30
31 Thanks,
32 Chun-Yu

Replies