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

Faster CryptoRNG #97

Merged
merged 1 commit into from
Oct 16, 2023
Merged

Faster CryptoRNG #97

merged 1 commit into from
Oct 16, 2023

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Oct 3, 2023

Dart's Random.secure is slow. For example, every call to nextInt() opens a new handle to /dev/urandom on Android and Linux, and there is no API to get N random bytes.

A simple workaround here is to use nextInt() to request 4 bytes at a time instead of 1 (this is the maximum allowed). It's not great yet, but in my tests I can generate around twice as many V4 UUIDs per second with this change.

Copy link
Owner

@daegalus daegalus left a comment

Choose a reason for hiding this comment

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

This a great idea and good improvement, thank you.

@daegalus daegalus merged commit 7069df5 into daegalus:main Oct 16, 2023
1 check passed
@rkistner rkistner deleted the faster-crypto-rng branch January 4, 2024 07:27
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