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

Add randomness pool mode for V4 UUID #80

Merged
merged 2 commits into from Jul 8, 2021

Conversation

puzpuzpuz
Copy link
Contributor

@puzpuzpuz puzpuzpuz commented May 18, 2021

Adds an optional randomness pool mode for Random (Version 4) UUID generation. The pool contains random bytes read from
the random number generator on demand in batches. Enabling the pool may improve the UUID generation throughput significantly.

Since the pool is stored on the Go heap, this feature may be a bad fit for security sensitive applications. That's why it's implemented as an opt-in feature.

Please treat this PR as a performance experiment.

Benchmarks

Environment: Ubuntu 20.04, go version go1.16.2 linux/amd64, i5-8300h

master branch:

BenchmarkUUID_New-8   	          597717	        1797 ns/op	      16 B/op	       1 allocs/op

This branch:

BenchmarkUUID_New-8   	          632412	        1809 ns/op	      16 B/op	       1 allocs/op
BenchmarkUUID_NewPooled-8   	 2058459	       579.7 ns/op	       0 B/op	       0 allocs/op

The BenchmarkUUID_NewPooled benchmark here stands for the pool mode. The pool size could be increased from current 256 bytes to gain a slightly better throughput, but that would come at the cost of larger memory footprint.

Adds an optional randomness pool mode for Random (Version 4)
UUID generation. The pool contains random bytes read from
the random number generator on demand in batches. Enabling
the pool may improve the UUID generation throughput
significantly.

Since the pool is stored on the Go heap, this feature may
be a bad fit for security sensitive applications. That's
why it's implemented as an opt-in feature.
Copy link
Collaborator

@pborman pborman left a comment

Choose a reason for hiding this comment

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

Over all this is fine, just need to add the note about non-threadsafe calls.

uuid.go Show resolved Hide resolved
@puzpuzpuz puzpuzpuz requested a review from pborman June 9, 2021 07:31
@pborman pborman merged commit 655bf50 into google:master Jul 8, 2021
@puzpuzpuz puzpuzpuz deleted the enhancement/entropy-pool branch July 9, 2021 07:44
@puzpuzpuz
Copy link
Contributor Author

@pborman thanks for the review!

@pierrre
Copy link

pierrre commented Jul 13, 2021

Hi !
Just a quick question:
why not use bufio.Reader ?
Is it to heavy/complex ?

@puzpuzpuz
Copy link
Contributor Author

why not use bufio.Reader ?
Is it to heavy/complex ?

@pierrre
TBH I didn't consider bufio.Reader when writing the code. The logic seems to be pretty straight-forward to me, so I kept the code simple and used a plain array + a position variable. But I guess, bufio.Reader would also work just fine.

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.

None yet

3 participants