Github user JanecekPetr commented on a diff in the pull request:
https://github.com/apache/storm/pull/2241#discussion_r129525496
--- Diff: storm-client/src/jvm/org/apache/storm/utils/TransferDrainer.java
---
@@ -21,101 +21,100 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.storm.generated.NodeInfo;
import org.apache.storm.messaging.IConnection;
import org.apache.storm.messaging.TaskMessage;
-import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TransferDrainer {
- private Map<Integer, ArrayList<ArrayList<TaskMessage>>> bundles = new
HashMap();
+ private Map<Integer, ArrayList<TaskMessage>> bundles = new HashMap();
+
private static final Logger LOG =
LoggerFactory.getLogger(TransferDrainer.class);
-
- public void add(HashMap<Integer, ArrayList<TaskMessage>>
taskTupleSetMap) {
- for (Map.Entry<Integer, ArrayList<TaskMessage>> entry :
taskTupleSetMap.entrySet()) {
- addListRefToMap(this.bundles, entry.getKey(), entry.getValue());
+
+ // Cache the msgs grouped by destination node
+ public void add(TaskMessage taskMsg) {
+ int destId = taskMsg.task();
+ ArrayList<TaskMessage> msgs = bundles.get(destId);
--- End diff --
Non-capturing lambdas only have a single instance in a generated private
static field, so the allocation cost is only paid once.
Of course, there is some extra cost in the indirection ... then again,
`computeIfAbsent()` is optimized in OpenJDK to only do a single hash + table
lookup, but `if (get() == null) put()` does two of each if the `get()` fails.
Overall the difference will be nonexistant / heavily dependant on the
prevailing branch.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---