From ef211f804882991f4cf31af6f18ff7db291954f5 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 7 Jul 2018 12:20:47 -0500 Subject: [PATCH] vfs: flatten resolution cache key This will require more storage if there are a lot of lookups with the same parent and differing paths, but otherwise, without more intentional structure sharing among paths, this should be better, and we can always revisit the arrangement later. Serializing the parent path segments should also make sure the same parent (semantically-speaking) contributes the same hash to the key. Previously, Metadata objects could prevent that, given their trivial, pointer-based hashes. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/vfs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index 14598ff..1e2705c 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -253,20 +253,20 @@ def clear_cache(): def is_valid_cache_key(x): """Return logically true if x looks like it could be a valid cache key (with respect to structure). Current valid cache entries: - (repo-id, path, parent, want_meta, dref) -> resolution + res:... -> resolution commit_oid -> commit commit_oid + ':r' -> rev-list i.e. rev-list -> {'.', commit, '2012...', next_commit, ...} """ # Suspect we may eventually add "(container_oid, name) -> ...", and others. x_t = type(x) - if x_t is tuple: - return len(x) == 5 if x_t is bytes: if len(x) == 20: return True if len(x) == 22 and x.endswith(b':r'): return True + if x.startswith('res:'): + return True def cache_get(key): global _cache @@ -759,7 +759,10 @@ def contents(repo, item, names=None, want_meta=True): yield x def _resolve_path(repo, path, parent=None, want_meta=True, deref=False): - cache_key = (repo.id(), tuple(path), parent, bool(want_meta), bool(deref)) + cache_key = b'res:%d%d%d:%s\0%s' \ + % (bool(want_meta), bool(deref), repo.id(), + ('/'.join(x[0] for x in parent) if parent else ''), + '/'.join(path)) resolution = cache_get(cache_key) if resolution: return resolution -- 2.39.2