From bcbaac03d45bbb2f8bab9d431f955e25dfb2eeaa Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 5 Aug 2024 17:48:48 -0300 Subject: [PATCH] feat: Add cache for get_ranked_tags_map --- aider/repomap.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/aider/repomap.py b/aider/repomap.py index 945ef7210..0252f460a 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -34,6 +34,10 @@ class RepoMap: tokens_per_char = None + # Cache for get_ranked_tags_map + _last_ranked_tags_map = None + _last_ranked_tags_map_args = None + def __init__( self, map_tokens=1024, @@ -409,6 +413,18 @@ class RepoMap: mentioned_fnames=None, mentioned_idents=None, ): + # Check if the arguments match the last call + current_args = ( + tuple(chat_fnames), + tuple(other_fnames) if other_fnames else None, + max_map_tokens, + frozenset(mentioned_fnames) if mentioned_fnames else None, + frozenset(mentioned_idents) if mentioned_idents else None, + ) + + if current_args == self._last_ranked_tags_map_args: + return self._last_ranked_tags_map + if not other_fnames: other_fnames = list() if not max_map_tokens: @@ -473,6 +489,11 @@ class RepoMap: middle = (lower_bound + upper_bound) // 2 spin.end() + + # Cache the result + self._last_ranked_tags_map = best_tree + self._last_ranked_tags_map_args = current_args + return best_tree tree_cache = dict()