Skip to content

Commit e73b1f6

Browse files
authored
Merge pull request #186 from pjcreath/profile-repomap
Add profiling information to repo map generation
2 parents e7299d3 + 929ec02 commit e73b1f6

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
aider/__version__.py
3434
aider/_version.py
3535
*.pyc
36+
.aider*
37+
env/

aider/io.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def __init__(
343343
self.bell_on_next_input = False
344344
self.notifications = notifications
345345
self.verbose = verbose
346+
self.profile_start_time = None
347+
self.profile_last_time = None
346348

347349
# Variables used to interface with base_coder
348350
self.coder = None
@@ -1373,6 +1375,25 @@ def tool_output(self, *messages, log_only=False, bold=False):
13731375

13741376
self.stream_print(*messages, style=style)
13751377

1378+
def profile(self, *messages, start=False):
1379+
if not self.verbose:
1380+
return
1381+
1382+
now = time.time()
1383+
message_str = " ".join(map(str, messages))
1384+
1385+
# Treat uninitialized as an implicit start.
1386+
if start or self.profile_start_time is None:
1387+
self.profile_start_time = now
1388+
self.stream_print(f"PROFILE: {message_str}")
1389+
else:
1390+
total_elapsed = now - self.profile_start_time
1391+
last_elapsed = now - self.profile_last_time
1392+
output_message = f"PROFILE: [+{last_elapsed:6.2f}s] {message_str} (total {total_elapsed:.2f}s)"
1393+
self.stream_print(output_message)
1394+
1395+
self.profile_last_time = now
1396+
13761397
def assistant_output(self, message, pretty=None):
13771398
if not message:
13781399
self.tool_warning("Empty response received from LLM. Check your provider account?")

aider/repomap.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ def __init__(
198198
self._mentioned_ident_similarity = 0.8
199199

200200
if self.verbose:
201+
self.io.tool_output(
202+
f"RepoMap loaded entries from tags cache: {len(self.TAGS_CACHE)}"
203+
)
201204
self.io.tool_output(
202205
f"RepoMap initialized with map_mul_no_files: {self.map_mul_no_files}"
203206
)
@@ -696,6 +699,8 @@ def get_ranked_tags(
696699
if tag.specific_kind == "import":
697700
file_imports[rel_fname].add(tag.name)
698701

702+
self.io.profile("process files")
703+
699704
if self.use_enhanced_map and len(file_imports) > 0:
700705
import_ast_mode = True
701706

@@ -791,6 +796,8 @@ def get_ranked_tags(
791796
weight = num_refs * use_mul * 2 ** (-1 * path_distance)
792797
G.add_edge(referencer, definer, weight=weight, key=ident, ident=ident)
793798

799+
self.io.profile("build graph")
800+
794801
if not references:
795802
pass
796803

@@ -808,6 +815,8 @@ def get_ranked_tags(
808815
except ZeroDivisionError:
809816
return []
810817

818+
self.io.profile("pagerank")
819+
811820
# distribute the rank from each source node, across all of its out edges
812821
ranked_definitions = defaultdict(float)
813822
for src in G.nodes:
@@ -822,6 +831,8 @@ def get_ranked_tags(
822831
ident = data["ident"]
823832
ranked_definitions[(dst, ident)] += data["rank"]
824833

834+
self.io.profile("distribute rank")
835+
825836
ranked_tags = []
826837
ranked_definitions = sorted(
827838
ranked_definitions.items(), reverse=True, key=lambda x: (x[1], x[0])
@@ -905,9 +916,11 @@ def get_ranked_tags_map(
905916

906917
# Check if the result is in the cache
907918
if use_cache and cache_key in self.map_cache:
919+
self.io.tool_output("DEBUG: get_ranked_tags_map cache hit")
908920
return self.map_cache[cache_key]
909921

910922
# If not in cache or force_refresh is True, generate the map
923+
self.io.tool_output("DEBUG: get_ranked_tags_map cache miss, generating map")
911924
start_time = time.time()
912925
result = self.get_ranked_tags_map_uncached(
913926
chat_fnames, other_fnames, max_map_tokens, mentioned_fnames, mentioned_idents
@@ -929,6 +942,7 @@ def get_ranked_tags_map_uncached(
929942
mentioned_fnames=None,
930943
mentioned_idents=None,
931944
):
945+
self.io.profile("get_ranked_tags_map_uncached", start=True)
932946
if not other_fnames:
933947
other_fnames = list()
934948
if not max_map_tokens:
@@ -943,6 +957,7 @@ def get_ranked_tags_map_uncached(
943957
ranked_tags = self.get_ranked_tags(
944958
chat_fnames, other_fnames, mentioned_fnames, mentioned_idents, True
945959
)
960+
self.io.profile("get_ranked_tags")
946961

947962
other_rel_fnames = sorted(set(self.get_rel_fname(fname) for fname in other_fnames))
948963
special_fnames = filter_important_files(other_rel_fnames)
@@ -992,6 +1007,7 @@ def get_ranked_tags_map_uncached(
9921007

9931008
middle = int((lower_bound + upper_bound) // 2)
9941009

1010+
self.io.profile("binary search and to_tree")
9951011
return best_tree
9961012

9971013
tree_cache = dict()

0 commit comments

Comments
 (0)