dschneider-pivotal commented on a change in pull request #6783:
URL: https://github.com/apache/geode/pull/6783#discussion_r706334841



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/delta/ZAddsDeltaInfo.java
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.delta;
+
+import static org.apache.geode.redis.internal.delta.DeltaType.ZADDS;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.geode.DataSerializer;
+
+public class ZAddsDeltaInfo implements DeltaInfo {

Review comment:
       To make ZAddsDeltaInfo produce less garbage consider changing it to have 
a "double[] scores" instead of "List<Double> scores". Every time we have a 
"double" and need to convert it to Double an object allocation happens. 
   Change it to have a single constructor "ZAddsDeltaInfo(int size)". The usage 
pattern would be to create it with the max size and then just call "add" for 
each pair you want to add. It looked to me like both places we create a 
ZAddsDeltaInfo we already know its max size. The array of doubles may not get 
completely filled but as long as you use the "deltas" List's size() to 
determine how many things are in the array you will be good. You might even 
want to add a size() method to this class that returns deltas.size().
   After making these changes make sure you don't have any places that use 
Double. They should all use "double". One place I noticed was when you call 
DataSerializer.writeDouble. You will want to change it to: 
DataSerializer.writePrimitiveDouble.

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZAddExecutor.java
##########
@@ -50,8 +52,18 @@ public RedisResponse executeCommand(Command command, 
ExecutionHandlerContext con
       return RedisResponse.error(zAddExecutorState.exceptionMessage);
     }
 
-    Object retVal = redisSortedSetCommands.zadd(command.getKey(),
-        new ArrayList<>(commandElements.subList(optionsFoundCount + 2, 
commandElements.size())),
+    int size = (commandElements.size() - optionsFoundCount - 2) / 2;
+    List<byte[]> members = new ArrayList<>(size);
+    List<Double> scores = new ArrayList<>(size);

Review comment:
       You can change this List<Double> to be "double[]" 

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/AbstractRedisData.java
##########
@@ -200,6 +202,15 @@ public void fromDelta(DataInput in) throws IOException, 
InvalidDeltaException {
         byte[] byteArray = DataSerializer.readByteArray(in);
         applyDelta(new AppendDeltaInfo(byteArray, sequence));
         break;
+      case ZADDS:
+        int numMembers = DataSerializer.readPrimitiveInt(in);

Review comment:
       If you make the changes I suggested to ZAddsDeltaInfo this could would 
look like this:
   int numMembers = DataSerializer.readPrimitiveInt(in);
   ZAddsDeltaInfo delta = new ZAddsDeltaInfo(numMembers);
   for (int i = 0; i < numMembers; i++) {
     byte[] member = DataSerializer.readByteArray(in);
     double score = DataSerializer.readPrimitiveDouble(in);
     delta.add(member, score);
   }
   applyDelta(delta);




-- 
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: [email protected]

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


Reply via email to