Skip to content

Bring optimised Jaccard code into main#72

Draft
johnlees wants to merge 3 commits into
mainfrom
jaccard_simd
Draft

Bring optimised Jaccard code into main#72
johnlees wants to merge 3 commits into
mainfrom
jaccard_simd

Conversation

@johnlees

Copy link
Copy Markdown
Member

Closes #68

@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.39073% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.56%. Comparing base (5612e0c) to head (707c60f).

Files with missing lines Patch % Lines
src/sketch/mod.rs 78.33% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #72      +/-   ##
==========================================
- Coverage   91.63%   91.56%   -0.07%     
==========================================
  Files          17       17              
  Lines        2964     3070     +106     
==========================================
+ Hits         2716     2811      +95     
- Misses        248      259      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/sketch/mod.rs Outdated
Comment on lines +257 to +259
for i in 0..BIN_BITS {
let orval = Self::bit_at_pos(*sign, i as u64) << leftshift;
usigs[sign_index / (u64::BITS as usize) * BIN_BITS + i] |= orval;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably use chunks_exact

Comment thread src/sketch/mod.rs

#[inline(always)]
fn bin_index(sign: u64, num_bins: u64) -> usize {
(((sign as u128) * (num_bins as u128)) >> u64::BITS) as usize

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems clever, need to confirm though

Comment thread src/sketch/mod.rs
pub fn get_usigs(&mut self) -> Vec<u64> {
std::mem::take(&mut self.usigs)
pub fn get_usigs(&mut self) -> SketchVec {
std::mem::replace(&mut self.usigs, aligned_sketch_vec())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-check this

Comment thread src/sketch/mod.rs Outdated
pub const SIGN_MOD: u64 = (1 << 61) - 1;
pub const BIN_BITS: usize = 16;
#[doc(hidden)]
pub const BBITS: usize = BIN_BITS;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be possible to remove? Might be used in tests

Comment thread src/distances/jaccard.rs
Comment on lines +127 to +130
fn random_match_correction(jaccard: f64) -> f64 {
let bb = (1u32 << (BIN_BITS as u32)) as f64;
((bb * jaccard - 1.0).max(0.0)) / (bb - 1.0)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check and confirm

Comment thread src/distances/jaccard.rs
}
}

#[cfg_attr(target_arch = "aarch64", allow(dead_code))]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe want these functions inline forced

Comment thread src/lib.rs
Comment on lines +12 to +13
//! for information on how to select good lengths. Jaccard distances include random match
//! correction for the retained sketch signature width.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite the same

Comment on lines +1 to +2
14412_3#82.contigs_velvet.fa.gz 14412_3#84.contigs_velvet.fa.gz 0.011049058 0.17300157
14412_3#84.contigs_velvet.fa.gz 14412_3#82.contigs_velvet.fa.gz 0.011049058 0.17300157

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diffs are larger

14412_3#84.contigs_velvet.fa.gz 5 10 0 0
TIGR4.fa.gz 0 0 7 10
14412_3#82.contigs_velvet.fa.gz 10 6 0 0
R6.fa.gz 0 0 10 9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised this changes

Name Sequence length Base frequencies Missing/ambig bases From reads Single strand Densified
test_1 1 [603, 330, 334, 603] 0 true false true
test_2 1 [617, 312, 314, 617] 0 true false true
test_1 91 [603, 330, 334, 603] 0 true false true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd

@johnlees johnlees marked this pull request as draft June 17, 2026 13:26
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.

Benchmarks of POC bitpacked code vs original

1 participant