Open
Description
I am migrating a project from Scala 2.12.8 to 2.13.0. While investigating a performance degradation, I came across an issue that's not new to Scala 2.13: Comparing integers like in the following piece of code
private final class EventPoint(val x: Int, val bbox: Rect2d, val isBBoxStart: Boolean)
private object EventPointOrdering extends Ordering[EventPoint] {
override def compare(p1: EventPoint, p2: EventPoint) = p1.x.compare(p2.x)
}
has unexpected overhead. I use this ordering to sort an EventPoint array and found that the use of EventPointOrdering accounts for 10% of the runtime:
(I used VisualVM for profiling and the program was compiled with full optimization and inlining.)
This call stack is terrifying, isn't it? I think that RIchInt (and all the other boxes for primitive types) should override compare instead of relying on OrderedProxy.
I solved my performance issue by using java.lang.Integer.compare directly.