Skip to content

T-298: perf(quartet_concordance): hoist buffer resize outside split loop#242

Open
ms609 wants to merge 2 commits into
cpp-searchfrom
feature/quartet-concordance-opt
Open

T-298: perf(quartet_concordance): hoist buffer resize outside split loop#242
ms609 wants to merge 2 commits into
cpp-searchfrom
feature/quartet-concordance-opt

Conversation

@ms609
Copy link
Copy Markdown
Owner

@ms609 ms609 commented May 13, 2026

Summary

  • Hoist n0/n1 buffer resize outside the split loop: was resize-per-char-per-split, now resize only when a new character has more states than current capacity (once per character in the worst case).
  • Compute max_state in the existing char-column caching pass — no extra loop added.
  • Add dev/benchmarks/bench_quartet_concordance.R for timing and profvis flame-graph.

Analysis notes (T-298)

Question Finding
Flat array vs NumericMatrix for output No difference: output writes are O(n_splits × n_chars), outside the inner loop; -O2 inlines Rcpp accessor to a single pointer dereference
int vs double n0/n1 are already int; output correctly uses double (decisive values can be half-integers)
Further micro-opts (split col ptr cache) Compiler hoists base + nrow * s under -O2; no profile evidence of residual overhead — left alone

Benchmark results (Windows, R 4.5.2, seed 42)

Size Taxa Splits Chars Time/call
small 25 23 50 <1 ms
medium 100 98 200 14 ms
large 300 298 400 186 ms

Test plan

  • GHA agent-check passes (run 25777319791)
  • No regression in test-QuartetConcordance tests

🤖 Generated with Claude Code

Resize n0/n1 only when a new character has more states than current
buffer capacity (once per character rather than once per taxon × split).
Also compute max_state in the existing char-column pass (no extra loop).

Adds dev/benchmarks/bench_quartet_concordance.R for timing at
small/medium/large scales and profvis flame-graph support.

Benchmarks (Windows, R 4.5): small (<1ms), medium (14ms), large (186ms)
per call at 25/100/300 taxa respectively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ms609 added a commit that referenced this pull request May 13, 2026
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