Skip to content

Conversation

@naoNao89
Copy link
Contributor

@naoNao89 naoNao89 commented Dec 7, 2025

Implement modular factorization architecture with Pollard-Rho, ECM, and Fermat algorithms. Adds Montgomery arithmetic optimization and u64 fast-path for improved u128 performance. Dynamic algorithm selection based on input size routes through unified entry point.

Fixes #1456


--- Testing: 12 ---
uutils: 12: 2 2 3
GNU:    12: 2 2 3
uutils time: real       0m0.007s
GNU time:    real       0m0.007s

--- Testing: 1000000007 ---
uutils: 1000000007: 1000000007
GNU:    1000000007: 1000000007
uutils time: real       0m0.005s
GNU time:    real       0m0.006s

--- Testing: 9999999999999999999 ---
uutils: 9999999999999999999: 3 3 1111111111111111111
GNU:    9999999999999999999: 3 3 1111111111111111111
uutils time: real       0m0.004s
GNU time:    real       0m0.007s

--- Testing: 18446744073709551557 ---
uutils: 18446744073709551557: 18446744073709551557
GNU:    18446744073709551557: 18446744073709551557
uutils time: real       0m0.004s
GNU time:    real       0m0.007s

--- Testing: 123456789012345678901234567890 ---
uutils: 123456789012345678901234567890: 2 3 3 3 5 7 13 31 37 211 241 2161 3607 3803 2906161
GNU:    123456789012345678901234567890: 2 3 3 3 5 7 13 31 37 211 241 2161 3607 3803 2906161
uutils time: real       0m0.004s
GNU time:    real       0m0.006s

--- Testing: 2305843009213693951 ---
uutils: 2305843009213693951: 2305843009213693951
GNU:    2305843009213693951: 2305843009213693951
uutils time: real       0m0.004s
GNU time:    real       0m0.007s

--- Testing: 6469693230 ---
uutils: 6469693230: 2 3 5 7 11 13 17 19 23 29
GNU:    6469693230: 2 3 5 7 11 13 17 19 23 29
uutils time: real       0m0.004s
GNU time:    real       0m0.006s

--- Testing: 340282366920938463463374607431768211297 ---
uutils: 340282366920938463463374607431768211297: 340282366920938463463374607431768211297
GNU:    340282366920938463463374607431768211297: 340282366920938463463374607431768211297
uutils time: real       0m0.004s
GNU time:    real       0m0.006s

--- Testing: 9223372036854775783 ---
uutils: 9223372036854775783: 9223372036854775783
GNU:    9223372036854775783: 9223372036854775783
uutils time: real       0m0.004s
GNU time:    real       0m0.007s

--- Testing: 18446744073709551615 ---
uutils: 18446744073709551615: 3 5 17 257 641 65537 6700417
GNU:    18446744073709551615: 3 5 17 257 641 65537 6700417
uutils time: real       0m0.010s
GNU time:    real       0m0.006s
Benchmark 1: ./target/release/factor 18446744073709551557 (64-bit prime near 2^64)
  Time (mean ± σ):      35.1 ms ±   1.8 ms    [User: 25.7 ms, System: 8.1 ms]
  Output: 18446744073709551557 (prime)

Benchmark 2: ./target/release/factor 9999999999999999999 (large u64)
  Time (mean ± σ):      34.8 ms ±   1.2 ms    [User: 25.7 ms, System: 7.9 ms]
  Output: 3 3 1111111111111111111

Benchmark 3: ./target/release/factor 123456789012345678901234567890 (97-bit u128)
  Time (mean ± σ):      36.3 ms ±   7.0 ms    [User: 26.0 ms, System: 8.1 ms]
  Output: 2 3 3 3 5 7 13 31 37 211 241 2161 3607 3803 2906161

Benchmark 4: ./target/release/factor 18446743979220271189 (64-bit semiprime)
  Time (mean ± σ):      36.3 ms ±   8.1 ms    [User: 25.9 ms, System: 8.1 ms]
  Output: 4294967279 4294967291

All inputs processed in ~35-36ms consistently

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 561e1cf to 3673060 Compare December 7, 2025 07:58
@naoNao89
Copy link
Contributor Author

naoNao89 commented Dec 7, 2025

@asder8215 👀

@naoNao89 naoNao89 marked this pull request as draft December 7, 2025 08:01
@oech3
Copy link
Contributor

oech3 commented Dec 7, 2025

Can this close #1456 ?

@github-actions
Copy link

github-actions bot commented Dec 7, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@asder8215
Copy link
Contributor

Wow, this looks awesome to see a highly optimized version of the factor command.

I won't have time to look at it today (most likely tomorrow afternoon), but this is good stuff right here

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 3673060 to 78e5601 Compare December 8, 2025 03:47
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 78e5601 to e92a74c Compare December 8, 2025 04:38
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@sylvestre sylvestre force-pushed the perf/u128-performance-only branch from e92a74c to e4125bf Compare December 8, 2025 07:00
@sylvestre
Copy link
Contributor

cool

a few things:

  • some jobs are failing
  • maybe add some benchmarks?!
  • maybe it is why codspeed isn't showing improvements
  • in comment #0 - i would prefer to have hyperfine output for benchmarks

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from e4125bf to 52d1aa4 Compare December 8, 2025 07:09
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 8, 2025

CodSpeed Performance Report

Merging #9587 will not alter performance

Comparing naoNao89:perf/u128-performance-only (fe6b0e5) with main (415d01c)

Summary

✅ 126 untouched
🆕 12 new
⏩ 7 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 factor_64bit_semiprime N/A 176.7 µs N/A
🆕 factorize_64bit_semiprime N/A 20.7 µs N/A
🆕 factor_medium_u64 N/A 353.6 µs N/A
🆕 factorize_96bit_composite N/A 97.3 µs N/A
🆕 factorize_large_prime N/A 17.5 µs N/A
🆕 factorize_small_u64 N/A 105 µs N/A
🆕 factorize_close_factors N/A 10.9 µs N/A
🆕 factor_batch_mixed N/A 348.6 µs N/A
🆕 factor_large_u64_prime N/A 279.1 µs N/A
🆕 factor_small_u64 N/A 43.3 ms N/A
🆕 factorize_32bit_semiprime N/A 10.5 µs N/A
🆕 factorize_120bit_mixed N/A 20.7 ms N/A

Footnotes

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

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from f2e738b to 2ae7cdd Compare December 8, 2025 08:04
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Congrats! The gnu test tests/stty/stty-invalid is now passing!
Congrats! The gnu test tests/stty/stty-pairs is now passing!
Note: The gnu test tests/mv/i-3 was skipped on 'main' but is now failing.
Note: The gnu test tests/stty/stty was skipped on 'main' but is now failing.
Note: The gnu test tests/stty/stty-row-col was skipped on 'main' but is now failing.

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 2ae7cdd to 57ca461 Compare December 8, 2025 08:09
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Congrats! The gnu test tests/stty/stty-invalid is now passing!
Congrats! The gnu test tests/stty/stty-pairs is now passing!
Note: The gnu test tests/mv/i-3 was skipped on 'main' but is now failing.
Note: The gnu test tests/stty/stty was skipped on 'main' but is now failing.
Note: The gnu test tests/stty/stty-row-col was skipped on 'main' but is now failing.

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from baeabd8 to 7884538 Compare December 8, 2025 08:57
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 7884538 to cffa831 Compare December 8, 2025 09:14
@naoNao89 naoNao89 closed this Dec 8, 2025
@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from cffa831 to 7c62885 Compare December 8, 2025 09:30
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 reopened this Dec 8, 2025
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 90f5f44 to 69e10cf Compare December 8, 2025 19:14
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 69e10cf to 21a1ae4 Compare December 9, 2025 18:42
@naoNao89 naoNao89 reopened this Dec 9, 2025
@github-actions
Copy link

github-actions bot commented Dec 9, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch 5 times, most recently from bb23135 to 55b9f46 Compare December 10, 2025 06:38
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 55b9f46 to b2c4afa Compare December 10, 2025 07:09
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch 2 times, most recently from aecb589 to 2140911 Compare December 10, 2025 09:07
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch 3 times, most recently from 4a0f720 to fa4e1a5 Compare December 10, 2025 16:23
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from fa4e1a5 to a46baa4 Compare December 10, 2025 16:48
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from a46baa4 to 3085bac Compare December 10, 2025 17:17
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the perf/u128-performance-only branch from 3085bac to 5b70e0a Compare December 10, 2025 17:36
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

@naoNao89
Copy link
Contributor Author

next phase for 400bit

time target/release/factor
 18042293517206497542309510624433271319838885652990797220840253733663197676853651276247377312     
DEBUG: Attempting yamaquasi SIQS for 287-bit number
DEBUG: yamaquasi found factor: 73 bits
18042293517206497542309510624433271319838885652990797220840253733663197676853651276247377312: 2 2 2 2 2 11 293 7189204372506229734671 24333278690998283582226208220580048953269361177999035383847458677
target/release/factor   1.72s user 0.03s system 378% cpu 0.463 total

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.

uutils' factor is much slower than GNU's coreutils factor

4 participants