Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft impl of JP06 pseudo-uniform sieve #65

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Nov 11, 2024

Plenty to do here still, but I wanted to check the temperature on adding something like this. I have some preliminary benchmarks but need more, as well as some sort of measurement of the quality of the candidate distribution.

Benchmarks:

Uniform sieve/(U128) Random prime
                        time:   [16.186 µs 16.271 µs 16.355 µs]
                        change: [-57.114% -56.686% -56.285%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  2 (2.00%) low mild
  3 (3.00%) high mild
Uniform sieve/(U1024) Random prime
                        time:   [3.7322 ms 3.8515 ms 3.9741 ms]
                        change: [-4.1998% -0.0392% +4.4595%] (p = 0.99 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
Uniform sieve/(U2048) Random prime
                        time:   [44.705 ms 48.435 ms 52.268 ms]
                        change: [-16.090% -6.0587% +4.9886%] (p = 0.27 > 0.05)
                        No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

Presets/(U128) Random prime
                        time:   [29.215 µs 29.282 µs 29.350 µs]
                        change: [-0.6125% -0.0475% +0.5168%] (p = 0.87 > 0.05)
                        No change in performance detected.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
  2 (2.00%) high mild
Presets/(U1024) Random prime
                        time:   [16.208 ms 17.986 ms 19.881 ms]
                        change: [-14.583% -1.9649% +13.994%] (p = 0.79 > 0.05)
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
Benchmarking Presets/(U2048) Random prime: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.2s, or reduce sample count to 60.
Presets/(U2048) Random prime
                        time:   [58.075 ms 68.075 ms 78.841 ms]
                        change: [-19.450% -0.2867% +23.699%] (p = 0.98 > 0.05)
                        No change in performance detected.
Found 7 outliers among 100 measurements (7.00%)
  6 (6.00%) high mild
  1 (1.00%) high severe

The above benchmark results are quite surprising to me. I expected the uniform sieve to be significantly slower than our PRIMEINC sieve. One odd thing is that I discovered by accident that when finding the upper bounds for algorithm2, using T::random_mod is significantly slower than T::random_bits (code here vs here). I can't quite explain why this is and have not (yet) benchmarked crypto-bigint.

@dvdplm dvdplm requested a review from fjarri November 11, 2024 21:47
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 47.74775% with 58 lines in your changes missing coverage. Please review.

Project coverage is 95.25%. Comparing base (4ea84ca) to head (82aa804).

Files with missing lines Patch % Lines
src/uniform_sieve.rs 47.27% 58 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
- Coverage   99.37%   95.25%   -4.13%     
==========================================
  Files           9       10       +1     
  Lines        1280     1390     +110     
==========================================
+ Hits         1272     1324      +52     
- Misses          8       66      +58     

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

@fjarri fjarri mentioned this pull request Nov 11, 2024
// λ(m) = 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099F002D0502D70DF7B64150D19B477A781987C56EBCDB7637842794D22D0D022010DC9BA1DB141FC9D07A9587E7A130D9DF6F9B67812800D00
// TODO(dp): Would love for this to be `const`. Or not here at all. Does it have any value, in some form?
#[allow(unused)]
fn calculate_m_and_lambda_m<T>() -> (T, T)
Copy link
Member

Choose a reason for hiding this comment

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

How long does that take, compared to prime searching? If it's not too long, we can just generate it in the sieve on every call. If it is, could be put in https://doc.rust-lang.org/std/sync/struct.LazyLock.html, but that requires std, so will have to be gated behind a feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a thought about moving it to a build.rs and spit out a file on disk with the values. That way it wouldn't bloat the binary. But that sucks in a lot of ways.

Another thought I had was to remove the code completely and add a git commit hash as a comment in the code, providing future readers a way to check how the constants were generated if they really care.

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.

2 participants