This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git


The following commit(s) were added to refs/heads/main by this push:
     new f30b757d perf(java): Optimize MetaStringDecoder (#1568)
f30b757d is described below

commit f30b757d50e2e73d7d455c4c2c457fc45f7a1f46
Author: LiangliangSui <[email protected]>
AuthorDate: Wed Apr 24 22:43:15 2024 +0800

    perf(java): Optimize MetaStringDecoder (#1568)
    
    
    
    ## What does this PR do?
    
    <!-- Describe the purpose of this PR. -->
    When `MetaStringDecoder` is decoding, it will read two bytes at a time
    from the `data` and then perform the operation. This PR determines
    whether to skip the byte value. If it does not skip the byte decoding,
    it will only read one byte from the data.
    
    ## Related issues
    
    ## Does this PR introduce any user-facing change?
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
    
    Signed-off-by: LiangliangSui <[email protected]>
---
 .../org/apache/fury/meta/MetaStringDecoder.java    | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/meta/MetaStringDecoder.java 
b/java/fury-core/src/main/java/org/apache/fury/meta/MetaStringDecoder.java
index 38835257..345663af 100644
--- a/java/fury-core/src/main/java/org/apache/fury/meta/MetaStringDecoder.java
+++ b/java/fury-core/src/main/java/org/apache/fury/meta/MetaStringDecoder.java
@@ -75,10 +75,15 @@ public class MetaStringDecoder {
       int byteIndex = bitIndex / 8;
       int intraByteIndex = bitIndex % 8;
       // Extract the 5-bit character value across byte boundaries if needed
-      int charValue =
-          ((data[byteIndex] & 0xFF) << 8)
-              | (byteIndex + 1 < data.length ? (data[byteIndex + 1] & 0xFF) : 
0);
-      charValue = (byte) ((charValue >> (11 - intraByteIndex)) & bitMask);
+      int charValue;
+      if (intraByteIndex > 3) {
+        charValue =
+            ((data[byteIndex] & 0xFF) << 8)
+                | (byteIndex + 1 < data.length ? (data[byteIndex + 1] & 0xFF) 
: 0);
+        charValue = (byte) ((charValue >> (11 - intraByteIndex)) & bitMask);
+      } else {
+        charValue = data[byteIndex] >> (3 - intraByteIndex) & bitMask;
+      }
       bitIndex += 5;
       decoded.append(decodeLowerSpecialChar(charValue));
     }
@@ -100,10 +105,15 @@ public class MetaStringDecoder {
       int intraByteIndex = bitIndex % 8;
 
       // Extract the 6-bit character value across byte boundaries if needed
-      int charValue =
-          ((data[byteIndex] & 0xFF) << 8)
-              | (byteIndex + 1 < data.length ? (data[byteIndex + 1] & 0xFF) : 
0);
-      charValue = ((byte) ((charValue >> (10 - intraByteIndex)) & bitMask));
+      int charValue;
+      if (intraByteIndex > 2) {
+        charValue =
+            ((data[byteIndex] & 0xFF) << 8)
+                | (byteIndex + 1 < data.length ? (data[byteIndex + 1] & 0xFF) 
: 0);
+        charValue = ((byte) ((charValue >> (10 - intraByteIndex)) & bitMask));
+      } else {
+        charValue = data[byteIndex] >> (2 - intraByteIndex) & bitMask;
+      }
       bitIndex += 6;
       decoded.append(decodeLowerUpperDigitSpecialChar(charValue));
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to