Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

⚡ Optimize AmpliconGenerator.add_repliconf with O(1) checks

What:

  • Added self._repliconfs_set (set) to AmpliconGenerator.
  • Updated add_repliconf to use the set for membership check (O(1)) instead of the list (O(N)).
  • Maintained synchronization between repliconfs (list) and _repliconfs_set in add_repliconf and remove_repliconf.

Why:

  • add_repliconf was performing a linear scan of repliconfs to prevent duplicates, leading to O(N^2) complexity when adding N repliconfs.
  • This optimization makes the check O(1), reducing the total time to add N repliconfs to O(N).

Measured Improvement:

  • Baseline: ~4.02 seconds for adding 5000 Repliconfs.
  • Optimized: ~0.02 seconds for adding 5000 Repliconfs.
  • Speedup: ~200x.

PR created automatically by Jules for task 17538939382487651922 started by @fangfufu

google-labs-jules bot and others added 4 commits January 26, 2026 03:54
…91)

This change pre-calculates the reverse complement of the primer in the `Repliconf` object and reuses it during amplicon generation. This avoids repeated expensive `DNA.reverse_complement()` calls inside the `get_amplicons` loop, leading to a measured ~17% performance improvement in a benchmark scenario with many potential amplicons.

Changes:
- Added `rev_comp_primer` attribute to `Repliconf` in `src/amplifyp/repliconf.py`.
- Updated `AmpliconGenerator._construct_amplicon_sequence` in `src/amplifyp/amplicon.py` to use `rev_conf.rev_comp_primer`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This change modifies `src/amplifyp/gui2/map_view.py` to correctly visualize amplicons that wrap around the origin of a circular DNA template. Previously, such amplicons were not drawn (or drawn incorrectly with negative width). Now, they are drawn as two segments: one from the start index to the end of the template, and another from the beginning of the template to the end index. The size label is placed on the longer of the two segments.

Tested with a reproduction script mocking the GUI environment and verified no regressions with existing tests.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Pre-calculate `_seq_upper` in `__init__` to avoid repeated string
allocations in `_count_bases`, `__eq__`, and `__hash__`. Reuse the
original sequence string if it is already uppercase to save memory.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Fufu Fang <fangfufu2003@gmail.com>
Introduced a private set `_repliconfs_set` to store `Repliconf` objects for fast membership testing.
Updated `add_repliconf` and `remove_repliconf` to maintain synchronization between the public list `repliconfs` and the new set.
This reduces the complexity of checking for duplicates from O(N) to O(1), significantly improving performance when adding many replication configurations.

Benchmarks showed a reduction from ~4.02s to ~0.02s for adding 5000 repliconfs.

Added `tests/test_amplicon_generator_optimization.py` to verify internal consistency and regression testing.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fangfufu fangfufu closed this Jan 26, 2026
@fangfufu fangfufu deleted the perf-amplicon-generator-optimization-17538939382487651922 branch January 26, 2026 11:38
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.

1 participant