feat: Estimate initial middle value for binary search in get_ranked_tags_map

This commit is contained in:
Paul Gauthier (aider) 2024-08-05 16:17:03 -03:00
parent b19795228f
commit ba1c8d1701

View file

@ -395,13 +395,21 @@ class RepoMap:
chat_rel_fnames = [self.get_rel_fname(fname) for fname in chat_fnames]
dump(max_map_tokens)
# Guess a small starting number to help with giant repos
middle = min(max_map_tokens // 50, num_tags)
self.tree_cache = dict()
# Estimate initial middle value
sample_size = min(100, num_tags)
sample_tree = self.to_tree(ranked_tags[:sample_size], chat_rel_fnames)
sample_tokens = self.token_count(sample_tree)
if sample_tokens > 0:
estimated_tags = int((max_map_tokens / sample_tokens) * sample_size)
middle = min(estimated_tags, num_tags)
else:
middle = min(max_map_tokens // 50, num_tags)
dump(max_map_tokens, sample_size, sample_tokens, estimated_tags, middle)
while lower_bound <= upper_bound:
dump(lower_bound, middle, upper_bound)