Skip to content

sort: Use fastrand#11125

Draft
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:sort-nanorng
Draft

sort: Use fastrand#11125
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:sort-nanorng

Conversation

@oech3
Copy link
Contributor

@oech3 oech3 commented Feb 26, 2026

3189432 -> 3179752 byte

Summary
  sort-nano -R /etc/pacman.conf ran
    1.05 ± 0.27 times faster than sort -R /etc/pacman.conf

non-crypto rng with getrandom should be safe.

Comment on lines +2905 to +2906
use nanorand::Rng;
nanorand::WyRand::new().generate::<u128>().to_ne_bytes()
Copy link
Contributor

Choose a reason for hiding this comment

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

WyRand has 64 bit output size, which we use to generate 128 bit salt?

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 guess it is just generating 64bit twice.

@anastygnome
Copy link
Contributor

anastygnome commented Feb 27, 2026

Hey, as a sidenote, you can use

git push <remotename> <commit SHA>:<remotebranchname>

to push only one commit to a remote.

@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

I deliberately split 2 commit to run bench only and drop later.

@xtqqczze
Copy link
Contributor

@oech3 Going forward, you could use NOMERGE as the commit message for clarity in these scenarios.

@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

No need. This is draft.

@xtqqczze
Copy link
Contributor

No need. This is draft.

I mean, in future.

I think like #11123, you should use fastrand in this PR, since uu_sort already it as a transitive dependency.

@oech3 oech3 changed the title sort: Use nanorand sort: Use fastrand Feb 27, 2026
@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

since uu_sort already it as a transitive dependency.

What crate? Also does shuf have similar dep (though shuf might require high-quality rng...)?

@xtqqczze
Copy link
Contributor

fastrand is a dependency of tempfile.

@xtqqczze
Copy link
Contributor

though shuf might require high-quality rng...)?

We can still get some improvement changing from default RNG (ChaCha20) to ChaCha8.

@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

Since CodSpeed might not report anything:
3189320 -> 3179328 byte

Summary
  sort-fastrand -R /etc/pacman.conf ran
    1.00 ± 0.21 times faster than sort-main -R /etc/pacman.conf

@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

This will be draft until #11123 was merged.

@xtqqczze
Copy link
Contributor

There might be no statistical significant difference between all three implementations, but one less dependency is a win.

@oech3
Copy link
Contributor Author

oech3 commented Feb 27, 2026

(btw, I was considering to remove rng dep from fuzzer by reusing ASLR provided pointer address...)

@xtqqczze
Copy link
Contributor

(btw, I was considering to remove rng dep from fuzzer by reusing ASLR provided pointer address...)

I don't know, this approach might be limited by low entropy (especially on 32-bit systems)

@oech3 oech3 force-pushed the sort-nanorng branch 2 times, most recently from 3895fcd to 9325b00 Compare March 3, 2026 18:14
@github-actions
Copy link

github-actions bot commented Mar 3, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.

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.

3 participants