Skip to content

Commit

Permalink
Add a cache for working_directory() of containerized tool-info module
Browse files Browse the repository at this point in the history
The goal is to avoid the multiprocessing overhead for this method,
which is called often but always returns the same result.
The multiprocessing overhead is typically not large,
but in some situations it is:
python/cpython#98493

On systems that are affect by this, it can save several minutes of
execution time if there are 10000 runs.
  • Loading branch information
PhilippWendler committed Nov 4, 2022
1 parent bc08946 commit f9868a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions benchexec/containerized_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def _add_proxy_function(cls, method_name, method):
def proxy_function(self, *args, **kwargs):
return self._forward_call(method_name, args, kwargs)

if method_name == "working_directory":
# Add a cache. This method is called per run but would always return the
# same result. On some systems the calls are slow and this is worth it:
# https://github.com/python/cpython/issues/98493
proxy_function = functools.lru_cache(proxy_function)

setattr(cls, member_name, proxy_function)


Expand Down

0 comments on commit f9868a4

Please sign in to comment.