App: Remove ResultCache
App.ResultCache is a horrible piece of software, now superseded by functools.cache, with no measurable performance benefit as of now. Remove it. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d4fa311771
commit
c471388fba
1 changed files with 3 additions and 55 deletions
|
|
@ -10,7 +10,7 @@ import sys
|
|||
|
||||
from enum import Enum, auto
|
||||
from functools import cache
|
||||
from typing import TYPE_CHECKING, Any, cast, override
|
||||
from typing import TYPE_CHECKING, Any, override
|
||||
|
||||
from .lib.App import App as Base
|
||||
from .lib.Distro import Distro
|
||||
|
|
@ -35,38 +35,6 @@ if TYPE_CHECKING:
|
|||
|
||||
# --------------------------------------------------------------------- Helpers
|
||||
|
||||
class ResultCache(object):
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__cache: dict[str, Any] = {}
|
||||
|
||||
def run(self, func: Any, args: list[Any]) -> object:
|
||||
d = self.__cache
|
||||
depth = 0
|
||||
keys = [func.__name__] + args
|
||||
sz = len(keys)
|
||||
for k in keys:
|
||||
if k is None:
|
||||
k = 'None'
|
||||
else:
|
||||
k = str(k)
|
||||
depth += 1
|
||||
# log(DEBUG, 'depth = ', depth, 'key = ', k, 'd = ', str(d))
|
||||
if k in d:
|
||||
if sz == depth:
|
||||
return d[k]
|
||||
d = d[k]
|
||||
continue
|
||||
if sz == depth:
|
||||
r = func(*args)
|
||||
d[k] = r
|
||||
return r
|
||||
d = d[k] = {}
|
||||
# d = d[k]
|
||||
raise Exception(
|
||||
'cache algorithm failed for function', func.__name__, 'in depth', depth
|
||||
)
|
||||
|
||||
class Scope(Enum):
|
||||
Self = auto()
|
||||
One = auto()
|
||||
|
|
@ -201,25 +169,6 @@ class App(Base):
|
|||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
def __get_project_refs_cached(
|
||||
self,
|
||||
buf: list[str],
|
||||
visited: set[str],
|
||||
spec: str,
|
||||
section: str,
|
||||
key: str,
|
||||
add_self: bool,
|
||||
scope: Scope,
|
||||
names_only: bool,
|
||||
) -> list[str]:
|
||||
return cast(
|
||||
'list[str]',
|
||||
self.__res_cache.run(
|
||||
self.__get_project_refs,
|
||||
[buf, visited, spec, section, key, add_self, scope, names_only],
|
||||
),
|
||||
)
|
||||
|
||||
def __get_project_refs(
|
||||
self,
|
||||
buf: list[str],
|
||||
|
|
@ -259,7 +208,7 @@ class App(Base):
|
|||
val = val.strip()
|
||||
if not (len(val)):
|
||||
continue
|
||||
self.__get_project_refs_cached(
|
||||
self.__get_project_refs(
|
||||
buf,
|
||||
visited,
|
||||
val,
|
||||
|
|
@ -360,7 +309,6 @@ class App(Base):
|
|||
self.__opt_verbose: bool | None = None
|
||||
self.__top_name: str | None = None
|
||||
self.__distro = distro
|
||||
self.__res_cache = ResultCache()
|
||||
self.___topdir: str | None = None
|
||||
self.___pretty_topdir: str | None = None
|
||||
self.__exec_context: ExecContext | None = None
|
||||
|
|
@ -626,7 +574,7 @@ class App(Base):
|
|||
visited: set[str] = set()
|
||||
for name in projects:
|
||||
rr: list[str] = []
|
||||
self.__get_project_refs_cached(
|
||||
self.__get_project_refs(
|
||||
rr, visited, name, section, key, add_self, scope, names_only
|
||||
)
|
||||
# TODO: this looks like a performance hogger
|
||||
|
|
|
|||
Loading…
Reference in a new issue