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

ping: optimize random number generation #1658

Merged
merged 1 commit into from
Jul 13, 2022
Merged

Conversation

marten-seemann
Copy link
Contributor

  1. We shouldn't use time-seeded random numbers. They contain very, very little entropy.
  2. We only need to initialize a math/rand random number generator once per Ping invocation.
  3. We don't need to use go-ipfs-util for this, bringing down the number of dependencies (therefore: part of After repo consolidation, prune deps #1646).

Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

look good. Did you do any benchmark to measure the actual perf optimization here? I would expect time seeded randomness to be pretty fast so curious to see if there was any actual perf benefit.

@marten-seemann
Copy link
Contributor Author

Initializing from crypto/rand is minimally slower, but then we only do it once per Ping.

BenchmarkTimeSeededRand-10        100039             11698 ns/op
BenchmarkCryptoRand-10             95367             11659 ns/op

@marten-seemann marten-seemann merged commit 7facd81 into master Jul 13, 2022
@ajnavarro ajnavarro mentioned this pull request Aug 24, 2022
72 tasks
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