nathanwilliams-ct commented on issue #2176:
URL: https://github.com/apache/buildstream/issues/2176#issuecomment-5316587262
From comment thread:
"""
hmm.. Instead of storing the result of _dependencies here, it might be worth
refactoring _dependencies to directly cache it's own results, so it can return
the cached result after the first call, whenever it's called anywhere instead
of just here. I don't think __build_dependencies or __runtime_dependencies is
ever updated after an Element is first initialised in _new_from_load_element.
(Although _add_build_dependency might be a problem? that would need
investigating, but you could clear the cache, in that method..)
...
__dependency_set_cache: dict[str,set[Element]] = {}
def __dependencies(...) -> ...:
# Check if we already calculated this set of dependencies
dependency_set_cache_key = f"{scope}, {recurse}" # (probably need to
include the _dependencies 'visited' argument here too...)
if (dependencies :=
self.__dependency_set_cache.get(dependency_set_cache_key)) is not None:
for element in dependencies:
yield element
return
# Calculate result/visited
....
# Store result for next time
self.__build_dependencies_set[dependency_set_cache_key] = result # ( or
'visited' from the recursive visit function)
It will need some thinking, but maybe it would even be appropriate to use
functools @cache annotation? https://docs.python.org/3/library/functools.html
The recursive visit function might also benefit from the @cache annotation..
"""
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]