Skip to content

pre-index match data to eliminate redundant loops in assembly#38

Open
agentksimha wants to merge 4 commits into
humanai-foundation:mainfrom
agentksimha:refactor/optimize-find-best-assembly-match
Open

pre-index match data to eliminate redundant loops in assembly#38
agentksimha wants to merge 4 commits into
humanai-foundation:mainfrom
agentksimha:refactor/optimize-find-best-assembly-match

Conversation

@agentksimha

Copy link
Copy Markdown

find_best_assembly_match previously used 4 nested loops, reconstructing
a string pair_key and re-iterating all color buckets on every call
during the Step 4 assembly loop.

Changes:

  • Add _build_fragment_match_index() — called once at end of Step 3,
    flattens color buckets and indexes matches by fragment ID in both
    directions for O(1) neighbour lookup
  • Refactor find_best_assembly_match() to use the index — replaces the
    two inner loops with a single max() over a pre-flattened list
  • Add early exit when similarity >= 1.0
  • Add defaultdict/chain imports

Time complexity of the assembly loop drops from O(N² · A · R · C · M)
to O(P·M) for the one-time index build + O(N · K · M) for all assembly
calls combined, where K is actual neighbours (sparse) vs R (full set)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants