Add caching to use_reduce, vercmp, and catpkgsplit

Each of these functions is called repeatedly with the same arguments
many times. Cache sizes were selected to minimize memory use increase,
while still providing about the same speedup compared to a cache with
unbounded size. "emerge -uDvpU --with-bdeps=y @world" runtime decreases
from 44.32s -> 29.94s -- a 48% speedup, while the maximum value of the
RES column in htop increases from 280 MB -> 290 MB.

"emerge -ep @world" time slightly decreases from 18.77s -> 17.93, while
max observed RES value actually decreases from 228 MB -> 214 MB (similar
values observed across a few before/after runs).

Bug: https://bugs.gentoo.org/732378
Signed-off-by: Zac Medico <zmedico@gentoo.org>
(cherry picked from commit d9ee5b09664ab2255b62c1d52d554721ef8b716a)

Change-Id: I797433e060347810470a1f22b3a144e407aa10fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/portage_tool/+/3723354
Tested-by: Yi Chou <yich@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Yi Chou <yich@google.com>
2 files changed