netudima commented on code in PR #4785:
URL: https://github.com/apache/cassandra/pull/4785#discussion_r3187637592


##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -815,11 +814,21 @@ private ReadQuery getSliceCommands(QueryOptions options, 
ClientState state, Colu
         if (filter == null || filter.isEmpty(table.comparator))
             return ReadQuery.empty(table);
 
-        List<DecoratedKey> decoratedKeys = new ArrayList<>(keys.size());
-        for (ByteBuffer key : keys)
+        List<DecoratedKey> decoratedKeys;
+        if (keys.size() == 1) // reduce allocations in collections for keys
         {
+            ByteBuffer key = keys.get(0);
             QueryProcessor.validateKey(key);
-            
decoratedKeys.add(table.partitioner.decorateKey(ByteBufferUtil.clone(key)));
+            decoratedKeys = 
Collections.singletonList(table.partitioner.decorateKey(key));
+        }
+        else
+        {
+            decoratedKeys = new ArrayList<>(keys.size());
+            for (ByteBuffer key : keys)
+            {
+                QueryProcessor.validateKey(key);

Review Comment:
   I prefer to optimize for a typical scenario, here we will make the code much 
more complex to support a failure scenario.
   In the failure scenario we raise exceptions and so, it is already quite slow 
in any case.
   So, such low level optimization (we speak about saving less than 1 percent 
here) like reducing of allocations for a failure scenario does not worth 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: [email protected]

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


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

Reply via email to