Skip to content

Optimize factorization hot paths (~25% speedup on factorize64)#67

Merged
sylvestre merged 3 commits intouutils:mainfrom
sylvestre:perf
Mar 24, 2026
Merged

Optimize factorization hot paths (~25% speedup on factorize64)#67
sylvestre merged 3 commits intouutils:mainfrom
sylvestre:perf

Conversation

@sylvestre
Copy link
Copy Markdown
Contributor

  • Update tsqrt bound after extracting factors in trial division
  • Reorder primality check to after trial division in factorize64
  • Add 5th/7th perfect power checks in factorize128_advanced
  • Add #[inline] on is_prime64, is_prime64_miller, is_prime32_miller
  • Pre-allocate vectors in factorization and primality functions
  • Use /= in trial division inner loops

- Update tsqrt bound after extracting factors in trial division
- Reorder primality check to after trial division in factorize64
- Add 5th/7th perfect power checks in factorize128_advanced
- Add #[inline] on is_prime64, is_prime64_miller, is_prime32_miller
- Pre-allocate vectors in factorization and primality functions
- Use /= in trial division inner loops
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 85.29412% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.07%. Comparing base (3f5db7d) to head (81c5f3b).
⚠️ Report is 29 commits behind head on main.

Files with missing lines Patch % Lines
src/nt_funcs.rs 84.37% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #67      +/-   ##
==========================================
+ Coverage   78.64%   85.07%   +6.42%     
==========================================
  Files          13       15       +2     
  Lines        2585     3490     +905     
  Branches      230      246      +16     
==========================================
+ Hits         2033     2969     +936     
+ Misses        552      520      -32     
- Partials        0        1       +1     
Flag Coverage Δ
macos_latest 84.95% <85.29%> (+7.31%) ⬆️
ubuntu_latest 84.52% <85.29%> (+6.34%) ⬆️
windows_latest 17.33% <44.11%> (+2.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq bot commented Mar 24, 2026

Merging this PR will improve performance by 52.23%

⚡ 1 improved benchmark
✅ 19 untouched benchmarks
⏩ 9 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation num-prime (this crate) 24.8 ms 16.3 ms +52.23%

Comparing sylvestre:perf (81c5f3b) with main (309566b)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

num-primes uses thread_rng() internally, making its benchmarks
non-deterministic. CodSpeed's instruction-counting simulation
amplifies this into huge false regressions. Gate all num-primes
bench_functions with #[cfg(feature = "num-primes")] and build
without the feature in CodSpeed CI.
num-primes uses thread_rng() internally, making its benchmarks
non-deterministic and causing false regressions in CodSpeed CI.

Remove num-primes from default features so it's excluded from CI
benchmarks. All num-primes bench_functions are gated behind
#[cfg(feature = "num-primes")] - use --features num-primes to
include them for local comparison.
@sylvestre sylvestre marked this pull request as ready for review March 24, 2026 21:58
@sylvestre sylvestre merged commit 395cef5 into uutils:main Mar 24, 2026
27 checks passed
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