Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/1447#discussion_r15037091
--- Diff: core/src/main/scala/org/apache/spark/rdd/PairRDDFunctions.scala
---
@@ -216,17 +216,17 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
def reducePartition(iter: Iterator[(K, V)]): Iterator[JHashMap[K, V]]
= {
val map = new JHashMap[K, V]
- iter.foreach { case (k, v) =>
- val old = map.get(k)
- map.put(k, if (old == null) v else func(old, v))
+ iter.foreach { pair =>
+ val old = map.get(pair._1)
--- End diff --
can we save the key into a variable here so we don't call _1 twice?
I was looking at the bytecode generated by pattern matching versus
non-pattern-matching, and the main difference is that we bypass some
unnecessary branches:
{code}
final def apply(x0$1: Tuple2): Unit = {
case <synthetic> val x1: Tuple2 = x0$1;
case4(){
if (x1.ne(null))
{
val k: Int = x1._1$mcI$sp();
val v: Int = x1._2$mcI$sp();
matchEnd3({
scala.this.Predef.println(scala.Int.box(k.+(v)));
scala.runtime.BoxedUnit.UNIT
})
}
else
case5()
};
case5(){
matchEnd3(throw new MatchError(x1))
};
matchEnd3(x: runtime.BoxedUnit){
()
}
{code}
---
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.
---