diff options
Diffstat (limited to 'plugins/code-modernization/scripts/make_shards.py')
| -rw-r--r-- | plugins/code-modernization/scripts/make_shards.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/code-modernization/scripts/make_shards.py b/plugins/code-modernization/scripts/make_shards.py index 1365d9bc..54ee208f 100644 --- a/plugins/code-modernization/scripts/make_shards.py +++ b/plugins/code-modernization/scripts/make_shards.py @@ -13,6 +13,7 @@ import codecs import collections import fnmatch import json +import math import os import re import sys @@ -48,6 +49,13 @@ CUT_WINDOW = 100 # how far a cut may move to land between two blocks of cod SMALL = 300 TINY_ESTATE = 30 # files; a tiny estate also fits in one shard (MAX_LOC lines) MAX_BYTES = 5_000_000 +# Estimated agents per 1,000 lines for each depth: code that is mostly plumbing, and very dense business logic. Taken from +# simulated runs (T-SQL procedures, C utilities) and, for the low end of standard, from a 30,000-line estate. +AGENTS_PER_KLOC = {'Standard': (15, 55), 'Thorough': (20, 190)} +SMALL_SHARD = {'Standard': 40, 'Thorough': 125} # a short dense file needs more per line: 10 + lines / 5, up to this +LENS_AGENTS = {'Standard': (15, 100), 'Thorough': (20, 250)} # a tiny estate, about 1,000 lines +LENS_MIN_TOP = {'Standard': 100, 'Thorough': 150} +TOKENS_PER_AGENT = 16_000 def too_broad(path): @@ -276,6 +284,23 @@ def split_long_files(shards, source): return out +def estimate(sizes, tiny): + """One line with the agents and tokens each depth is expected to need, from the number of lines in each shard.""" + def rounded(n): + return math.ceil(n / 10) * 10 + + parts = [] + for depth in AGENTS_PER_KLOC: + if tiny: + low, top = LENS_AGENTS[depth][0], max(LENS_MIN_TOP[depth], LENS_AGENTS[depth][1] * sum(sizes) / 1000) + else: + low = AGENTS_PER_KLOC[depth][0] * sum(sizes) / 1000 + top = sum(max(AGENTS_PER_KLOC[depth][1] * n / 1000, min(SMALL_SHARD[depth], 10 + n / 5)) for n in sizes) + low, top = max(rounded(low), 20), max(rounded(top), 30) + parts.append(f'{depth} {low} to {top} agents (about {low * TOKENS_PER_AGENT / 1e6:.1f}M to {top * TOKENS_PER_AGENT / 1e6:.1f}M tokens)') + return 'estimate: ' + '; '.join(parts) + ', from mostly plumbing to very dense business logic' + + def quoted(names): """Up to five file names for a note, quoted and shortened.""" return ', '.join(json.dumps(name[-80:]) + extra for name, extra in names[:5]) @@ -371,6 +396,8 @@ def main(argv): tiny = max(len(mapped), len(tree)) < TINY_ESTATE and max(loc, sum(n for _, n in tree)) <= MAX_LOC and not unread if unmapped_note and not tiny: # lens mode reads every file notes.append(unmapped_note) + # The map's sizes can be missing or out of date, so the files are counted. + print(estimate([s['loc'] if 'lines' in s else sum(count_lines(os.path.join(source, f)) or 0 for f in s['files']) or s['loc'] or 0 for s in shards], tiny)) if tiny: print(f'tiny estate: the system has fewer than {TINY_ESTATE} source files and at most {MAX_LOC} lines, so sharding adds little (run the workflow in lens mode).') for note in notes: |
