coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

factor:performance tuning

Open mattsu2020 opened this issue 1 month ago • 14 comments

Performance improvement for large numbers

fix this issue https://bugs.launchpad.net/ubuntu/+source/rust-coreutils/+bug/2131212

mattsu2020 avatar Nov 13 '25 14:11 mattsu2020

GNU testsuite comparison:

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

github-actions[bot] avatar Nov 13 '25 14:11 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Nov 14 '25 00:11 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Nov 14 '25 03:11 github-actions[bot]

could you please run hyperfine with the three programs? gnu, without the patch and with the patch and share the full results here? thanks :)

sylvestre avatar Nov 14 '25 08:11 sylvestre

GNU testsuite comparison:

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

github-actions[bot] avatar Nov 14 '25 10:11 github-actions[bot]

could you please run hyperfine with the three programs? gnu, without the patch and with the patch and share the full results here? thanks :)

Implementation Details

GMP 6.3.0 and GNU coreutils 9.5 were built and installed from source

Created factor_numbers_u128_repeat.txt (60 lines) as benchmark input, containing 6 composite numbers ranging from 64 to 128 bits repeated 10 times. Confirmed factorization completion across all 3 implementations and reran Hyperfine. All commands used the release profile (target/profiling/factor). Hyperfine execution results Command: hyperfine --warmup 3 --runs 12 “ < factor_numbers_u128_repeat.txt”

Implementation   Average time (s) Standard deviation (s) Minimum–Maximum (s)
GNU coreutils 9.5 ( local-gnu/bin/factor) 6.718 0.106 6.594 – 7.020
Old implementation (prev_worktree/target/profiling/factor) 6.125 1.942 2.648 – 8.508
After patch application (target/profiling/factor) 6.993 1.585 4.299 – 9.457

To reduce variance, we adjusted to 3 warm-ups + 12 measurements, but the Rust version still shows relatively high dispersion due to its randomized algorithm. For greater stability, consider running at times of low system load or using CPU pinning. Behavior with inputs exceeding 128 bits

For factor_numbers.txt (max ~260 bits), both the GNU version and the patched version achieved complete factorization. The old implementation returned factor: Factorization incomplete. Remainders exist. and exited with exit code 1. This confirms the improvement in support for large integers. factor_numbers_u128_repeat.txt

mattsu2020 avatar Nov 14 '25 11:11 mattsu2020

CodSpeed Performance Report

Merging #9261 will not alter performance

Comparing mattsu2020:factor_fix (4befbdd) with main (3108c45)

Summary

✅ 127 untouched
⏩ 6 skipped[^skipped]

[^skipped]: 6 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.

codspeed-hq[bot] avatar Nov 16 '25 14:11 codspeed-hq[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Nov 16 '25 14:11 github-actions[bot]

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Nov 17 '25 09:11 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Dec 01 '25 12:12 github-actions[bot]

Any idea why codspeed does not detect it?

sylvestre avatar Dec 07 '25 13:12 sylvestre

Any idea why codspeed does not detect it?

If I were to consider it, I would create test cases with large integers.

mattsu2020 avatar Dec 07 '25 14:12 mattsu2020

GNU testsuite comparison:

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

github-actions[bot] avatar Dec 07 '25 14:12 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Dec 08 '25 10:12 github-actions[bot]