Speed up majority/threshold consensus to O(kn)#272
Merged
Conversation
Compute majority-rule and threshold `Consensus()` (and `SplitFrequency()`) by counting every split's frequency in a single pass and keeping those at or above the threshold, replacing the O(k^2 n) multi-reference comparison. Majority splits each occur in more than half the trees, so they are pairwise (hence globally) compatible and form a valid tree directly. Time is linear in the number of trees (~25x faster at k = 1600; scaling exponent 0.97 vs 1.91). The count defaults to 128-bit hashing (O(kn), exact with overwhelming probability); `exact = TRUE` selects a slower deterministic bitmask count. `Consensus()` and `SplitFrequency()` share one counting core. Strict consensus (p = 1) keeps its already-linear single-reference path. Cites Jansson, Shen & Sung (2016); implementation informed by their FACT package (whose majority-consensus code proved unusable on edge cases, so no FACT source is incorporated). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #272 +/- ##
==========================================
+ Coverage 96.12% 96.19% +0.07%
==========================================
Files 81 81
Lines 6032 6039 +7
==========================================
+ Hits 5798 5809 +11
+ Misses 234 230 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Performance benchmark results
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Compute majority-rule and threshold
Consensus()(andSplitFrequency()) by counting every split's frequency in a single pass and keeping those at or above the threshold, replacing the O(k^2 n) multi-reference comparison. Majority splits each occur in more than half the trees, so they are pairwise (hence globally) compatible and form a valid tree directly. Time is linear in the number of trees (~25x faster at k = 1600; scaling exponent 0.97 vs 1.91).The count defaults to 128-bit hashing (O(kn), exact with overwhelming probability);
exact = TRUEselects a slower deterministic bitmask count.Consensus()andSplitFrequency()share one counting core. Strict consensus (p = 1) keeps its already-linear single-reference path.Cites Jansson, Shen & Sung (2016); implementation informed by their FACT package (whose majority-consensus code proved unusable on edge cases, so no FACT source is incorporated).