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 10:27:28 UTC

[GitHub] [shardingsphere] lwclover opened a new pull request, #16959: Optimize UUID performance

lwclover opened a new pull request, #16959:
URL: https://github.com/apache/shardingsphere/pull/16959

   Fixes #16958 .
   
   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
lwclover commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854705310


##########
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:
   jdk1.8 java.lang.String   
   ```
   public String replace(CharSequence target, CharSequence replacement) {
           return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(this).replaceAll(Matcher.quoteReplacement(replacement.toString()));
   }
   ```



-- 
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


[GitHub] [shardingsphere] TeslaCN merged pull request #16959: Optimize UUID performance

Posted by GitBox <gi...@apache.org>.
TeslaCN merged PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959


-- 
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


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

Posted by GitBox <gi...@apache.org>.
lwclover commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854687640


##########
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:
   I will do it



-- 
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


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

Posted by GitBox <gi...@apache.org>.
lwclover commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854724240


##########
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:
   Oh, I've learned a thing.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854723266


##########
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:
   > jdk1.8 java.lang.String
   > 
   > ```
   > public String replace(CharSequence target, CharSequence replacement) {
   >         return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(this).replaceAll(Matcher.quoteReplacement(replacement.toString()));
   > }
   > ```
   
   I see. The `String.replace` is improved since Java 9.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
TeslaCN commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854691477


##########
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:
   > > 
   > 
   > String.replace uses regular expressions.
   > commons-lang3 StringUtils.replace uses string Interception, restructuring.
   > Regular expressions are inefficient.
   > 
   > 
   
   String.replaceAll uses regex indeed, but String replace may not. Could you check it again?



-- 
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


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

Posted by GitBox <gi...@apache.org>.
lwclover commented on code in PR #16959:
URL: https://github.com/apache/shardingsphere/pull/16959#discussion_r854689202


##########
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:
   > 
   
   String.replace uses regular expressions.
   commons-lang3 StringUtils.replace uses string Interception, restructuring.
   Regular expressions are inefficient.
   
   



-- 
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