[ 
https://issues.apache.org/jira/browse/CASSANDRA-13760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16148400#comment-16148400
 ] 

Jeff Jirsa commented on CASSANDRA-13760:
----------------------------------------

The unit test run was clean. The dtest run timed out before I saw the result, 
so I've restarted it 
[here|https://builds.apache.org/view/A-D/view/Cassandra/job/Cassandra-devbranch-dtest/254/]

I'm +1 on the patch as long as the dtest run comes back no worse than the other 
trunk dtests.

I've made two small changes to the version I've uploaded as 
{{0001-Presize-collections.patch}} :

On 
{{src/java/org/apache/cassandra/db/compaction/CompactionStrategyManager.java}} 
, I added the expected size to the currGroup list made within the loop as well:

{code}
--- 
a/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
+++ 
b/src/java/org/apache/cassandra/db/compaction/AbstractCompactionStrategy.java
@@ -539,7 +539,7 @@ public abstract class AbstractCompactionStrategy
         Collections.sort(sortedSSTablesToGroup, 
SSTableReader.sstableComparator);

         Collection<Collection<SSTableReader>> groupedSSTables = new 
ArrayList<>();
-        Collection<SSTableReader> currGroup = new ArrayList<>();
+        Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);

         for (SSTableReader sstable : sortedSSTablesToGroup)
         {
@@ -547,7 +547,7 @@ public abstract class AbstractCompactionStrategy
             if (currGroup.size() == groupSize)
             {
                 groupedSSTables.add(currGroup);
-                currGroup = new ArrayList<>();
+                currGroup = new ArrayList<>(groupSize);
             }
         }
{code}

Similarly in 
{{src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java}} 
, added the initial size to the nested group as well:

{code}
--- a/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
+++ b/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java
@@ -223,14 +223,14 @@ public class LeveledCompactionStrategy extends 
AbstractCompactionStrategy

         for (Collection<SSTableReader> levelOfSSTables : 
sstablesByLevel.values())
         {
-            Collection<SSTableReader> currGroup = new ArrayList<>();
+            Collection<SSTableReader> currGroup = new ArrayList<>(groupSize);
             for (SSTableReader sstable : levelOfSSTables)
             {
                 currGroup.add(sstable);
                 if (currGroup.size() == groupSize)
                 {
                     groupedSSTables.add(currGroup);
-                    currGroup = new ArrayList<>();
+                    currGroup = new ArrayList<>(groupSize);
                 }
             }
{code}

Other than that, +1, looks good.




> presize collections
> -------------------
>
>                 Key: CASSANDRA-13760
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-13760
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Core
>            Reporter: Dave Brosius
>            Assignee: Dave Brosius
>            Priority: Trivial
>             Fix For: 4.x
>
>         Attachments: 0001-Presize-collections.patch, 13760.txt
>
>
> presize collections where sane, to avoid reallocs, or excess garbage



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to