akalash commented on a change in pull request #8577:
URL: https://github.com/apache/ignite/pull/8577#discussion_r545905042



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2.java
##########
@@ -301,6 +302,9 @@
     /** */
     protected boolean lastFinished;
 
+    /** map for cashing byte-array representations of strings */
+    private Map<String, byte[]> stringsMap;

Review comment:
       Why are you using a map here? A simple byte array is enough, isn't it?

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/direct/stream/v2/DirectByteBufferStreamImplV2.java
##########
@@ -584,7 +588,29 @@ public DirectByteBufferStreamImplV2(MessageFactory 
msgFactory) {
 
     /** {@inheritDoc} */
     @Override public void writeString(String val) {
-        writeByteArray(val != null ? val.getBytes() : null);
+        if (val != null) {
+            if (buf.capacity() < val.length()) {
+                if (stringsMap == null)
+                    stringsMap = new HashMap<>();
+
+                byte[] bytes = stringsMap.computeIfAbsent(val, s -> 
s.getBytes());
+
+                try {
+                    writeByteArray(bytes);
+                }
+                catch (Exception e) {

Review comment:
       I believe if an exception appears here, this whole object will be 
invalid, for example, arrOff would be incorrect, so perhaps it's not necessary 
to handle this exception here.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to