-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Performance improvements for factor #1525
Commits on May 24, 2020
-
factor: Refactor (eheh) around a
Factors
datatypeIt is clearer to see what is going on, as opposed to passing around an unmarked `Vec<u64>`, and there is a single place to add invariants checks. This is also a more compact memory representation: each prime factor is represented only once, with an additional byte for multiplicity. The performance impact is however not significant.
Configuration menu - View commit details
-
Copy full SHA for d9095a2 - Browse repository at this point
Copy the full SHA d9095a2View commit details -
factor: Move each factorisation method to its own module
Also decoupled the factorisation methods; now factor::factor contains the logic that chains the different algorithms and aggregates results. As a side-effect, rho::factor now performs extraneous allocations (as each recursive step creates a new `Factors` value, which is then aggregated into the previous one) but there is no significant performance impact.
Configuration menu - View commit details
-
Copy full SHA for a1b2522 - Browse repository at this point
Copy the full SHA a1b2522View commit details -
factor::factor: Use u64::trailing_zero instead of iterated division
No significant performance impact (most of the time is spent elsewhere), but an easy and satisfying fix nevertheless.
Configuration menu - View commit details
-
Copy full SHA for bc11e57 - Browse repository at this point
Copy the full SHA bc11e57View commit details -
factor::factor: Short-circuit the fallback to Pollard's rho
When the remainder is smaller than the max. entry in the table, it is guaranteed to be prime.
Configuration menu - View commit details
-
Copy full SHA for 418fd61 - Browse repository at this point
Copy the full SHA 418fd61View commit details -
factor::table: Remove extraneous calls to the primality test
50% performance improvement on factoring all numbers between 2 and 10⁶.
Configuration menu - View commit details
-
Copy full SHA for 1697406 - Browse repository at this point
Copy the full SHA 1697406View commit details -
Configuration menu - View commit details
-
Copy full SHA for e1a6dbe - Browse repository at this point
Copy the full SHA e1a6dbeView commit details -
factor::factor: Remove extraneous call to the primality test
Another 6.97% runtime improvement
Configuration menu - View commit details
-
Copy full SHA for 74054fe - Browse repository at this point
Copy the full SHA 74054feView commit details -
Configuration menu - View commit details
-
Copy full SHA for e3ecc81 - Browse repository at this point
Copy the full SHA e3ecc81View commit details -
factor::miller_rabbin: Refactor before extracting dividers
Replace iterated division with u64::trailing_zeros, hoist the selection of `mul` out of the loop, another cool 49.5% runtime improvement.
Configuration menu - View commit details
-
Copy full SHA for 6b9585b - Browse repository at this point
Copy the full SHA 6b9585bView commit details -
factor::miller_rabin: Extract dividers from the primality test
Another 36% improvement.
Configuration menu - View commit details
-
Copy full SHA for 8241037 - Browse repository at this point
Copy the full SHA 8241037View commit details -
Configuration menu - View commit details
-
Copy full SHA for 29eb8fd - Browse repository at this point
Copy the full SHA 29eb8fdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 30fd6a0 - Browse repository at this point
Copy the full SHA 30fd6a0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 543c7b9 - Browse repository at this point
Copy the full SHA 543c7b9View commit details -
factor::miller_rabin: Avoid unecessary exponentiation
Instead of computing a^r and a^(n-1) = a^(r 2ⁱ) separately, compute the latter by repeatedly squaring the former. 33.6% performance improvement
Configuration menu - View commit details
-
Copy full SHA for 36a2948 - Browse repository at this point
Copy the full SHA 36a2948View commit details -
factor::Factors::add: Split up to work without NLL
Co-authored-by: Roy Ivy III <rivy.dev@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 4c3682a - Browse repository at this point
Copy the full SHA 4c3682aView commit details