mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 01:04:59 +00:00
perf: cache TreeContext for each filename and re-use it
This commit is contained in:
parent
c8b5375709
commit
bb4ee1a221
1 changed files with 23 additions and 16 deletions
|
@ -60,6 +60,9 @@ class RepoMap:
|
|||
|
||||
self.main_model = main_model
|
||||
|
||||
self.tree_cache = {}
|
||||
self.tree_context_cache = {}
|
||||
|
||||
def token_count(self, text):
|
||||
len_text = len(text)
|
||||
if len_text < 200:
|
||||
|
@ -471,6 +474,7 @@ class RepoMap:
|
|||
if key in self.tree_cache:
|
||||
return self.tree_cache[key]
|
||||
|
||||
if rel_fname not in self.tree_context_cache:
|
||||
code = self.io.read_text(abs_fname) or ""
|
||||
if not code.endswith("\n"):
|
||||
code += "\n"
|
||||
|
@ -488,7 +492,10 @@ class RepoMap:
|
|||
# header_max=30,
|
||||
show_top_of_file_parent_scope=False,
|
||||
)
|
||||
self.tree_context_cache[rel_fname] = context
|
||||
|
||||
context = self.tree_context_cache[rel_fname]
|
||||
context.clear_lines_of_interest()
|
||||
context.add_lines_of_interest(lois)
|
||||
context.add_context()
|
||||
res = context.format()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue