You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/04/20 12:12:56 UTC

[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #16959: Optimize UUID performance

TeslaCN commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854060653


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java:
##########
@@ -31,8 +33,8 @@ public void init() {
     }
     
     @Override
-    public synchronized Comparable<?> generateKey() {
-        return UUID.randomUUID().toString().replaceAll("-", "");
+    public Comparable<?> generateKey() {
+        return StringUtils.replace(new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong()).toString(), "-", "");

Review Comment:
   Consider introducing a variable of ThreadLocalRandom.



##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java:
##########
@@ -31,8 +33,8 @@ public void init() {
     }
     
     @Override
-    public synchronized Comparable<?> generateKey() {
-        return UUID.randomUUID().toString().replaceAll("-", "");
+    public Comparable<?> generateKey() {
+        return StringUtils.replace(new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong()).toString(), "-", "");

Review Comment:
   Why use the `StringUtils`? What is the different between `StringUtils` and `String.replace`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org