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).

Signed-off-by: Zac Medico <>
(cherry picked from commit d9ee5b09664ab2255b62c1d52d554721ef8b716a)

Change-Id: I797433e060347810470a1f22b3a144e407aa10fd
Tested-by: Yi Chou <>
Reviewed-by: Mike Frysinger <>
Commit-Queue: Yi Chou <>
2 files changed