Change trackerList to a LinkedList 74/14474/1
authorRobert Varga <rovarga@cisco.com>
Sun, 25 Jan 2015 08:50:11 +0000 (09:50 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 25 Jan 2015 09:07:19 +0000 (10:07 +0100)
The trackers are being added to the end and usually remove in a linear
fashion. An ArrayList's remove() method makes sure the backing array is
packed -- which means we end up copying the array over and over again.

Changing the trackerList to a LinkedList removes the need for copying at
the expense of memory footprint and cache locality.

Change-Id: I3e40487798eb64713ed4526f53a0a8c385a9a778
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java

index ab11c5bd845d5926fb143f6703c8e7f2df7caad6..462c94ec8a40736cc005c994b74520d9111c3430 100644 (file)
@@ -18,11 +18,11 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import com.google.protobuf.ByteString;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -85,7 +85,7 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
 
     private Cancellable heartbeatSchedule = null;
 
-    private final Collection<ClientRequestTracker> trackerList = new ArrayList<>();
+    private final Collection<ClientRequestTracker> trackerList = new LinkedList<>();
 
     protected final int minReplicationCount;