-
Notifications
You must be signed in to change notification settings - Fork 0
fix: for perf improvement using fast random #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38458b5
fix: for perf improvemet using fast random
kotharironak 395b637
fix spotless issues
kotharironak 1ebb589
addressed the latest comments
kotharironak 0566d8f
need to extend supress warning for jackson lib
kotharironak 803ee86
addressed the comments
kotharironak ed3a0c5
pushing refactored code
kotharironak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...-context-utils/src/main/java/org/hypertrace/core/grpcutils/context/FastUUIDGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.hypertrace.core.grpcutils.context; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
public class FastUUIDGenerator { | ||
/** | ||
* This function generates UUIDs using ThreadLocalRandom, which is faster and doesn't block like | ||
* the default randomUUID method that relies on /dev/random. It's suitable for most random UUID | ||
* needs. | ||
*/ | ||
public static UUID randomUUID() { | ||
long mostSigBits = ThreadLocalRandom.current().nextLong(); | ||
long leastSigBits = ThreadLocalRandom.current().nextLong(); | ||
|
||
// Set the version (4) For random UUID | ||
mostSigBits &= 0xFFFFFFFFFFFF0FFFL; | ||
mostSigBits |= 0x0000000000004000L; | ||
// Set variant to RFC 4122 | ||
leastSigBits &= 0x3FFFFFFFFFFFFFFFL; | ||
leastSigBits |= 0x8000000000000000L; | ||
|
||
return new UUID(mostSigBits, leastSigBits); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be public? Doesn't need a new release, but next time you're in here can you move this to package private since it's an internal impl detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially thought of it to our own lib so it can be used. But, I think, we can make it private, anywhere else we can use the third-party library that is already there in most of the projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laxmanchekka @aaron-steinfeld https://github.com/hypertrace/java-grpc-utils/pull/50/files