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.main_model = main_model
|
||||||
|
|
||||||
|
self.tree_cache = {}
|
||||||
|
self.tree_context_cache = {}
|
||||||
|
|
||||||
def token_count(self, text):
|
def token_count(self, text):
|
||||||
len_text = len(text)
|
len_text = len(text)
|
||||||
if len_text < 200:
|
if len_text < 200:
|
||||||
|
@ -471,24 +474,28 @@ class RepoMap:
|
||||||
if key in self.tree_cache:
|
if key in self.tree_cache:
|
||||||
return self.tree_cache[key]
|
return self.tree_cache[key]
|
||||||
|
|
||||||
code = self.io.read_text(abs_fname) or ""
|
if rel_fname not in self.tree_context_cache:
|
||||||
if not code.endswith("\n"):
|
code = self.io.read_text(abs_fname) or ""
|
||||||
code += "\n"
|
if not code.endswith("\n"):
|
||||||
|
code += "\n"
|
||||||
|
|
||||||
context = TreeContext(
|
context = TreeContext(
|
||||||
rel_fname,
|
rel_fname,
|
||||||
code,
|
code,
|
||||||
color=False,
|
color=False,
|
||||||
line_number=False,
|
line_number=False,
|
||||||
child_context=False,
|
child_context=False,
|
||||||
last_line=False,
|
last_line=False,
|
||||||
margin=0,
|
margin=0,
|
||||||
mark_lois=False,
|
mark_lois=False,
|
||||||
loi_pad=0,
|
loi_pad=0,
|
||||||
# header_max=30,
|
# header_max=30,
|
||||||
show_top_of_file_parent_scope=False,
|
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_lines_of_interest(lois)
|
||||||
context.add_context()
|
context.add_context()
|
||||||
res = context.format()
|
res = context.format()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue