-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Implement ListBuffer.isEmpty / nonEmpty / head efficiently #5802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate a bit on the kind of benchmarks you performed?
// Override with efficient implementations using the extra size information available to ListBuffer. | ||
override def isEmpty: Boolean = len == 0 | ||
override def nonEmpty: Boolean = len > 0 | ||
override def head: A = if (len > 0) start.asInstanceOf[::[A]].head else Nil.head |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one doesn't look very cute.. start.head
would be a virtual call with two cases, so C2 should be able to inline it. But before C2 it's probably slower than the monomorphic calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are probably right about head
. I removed that one.
Uses the extra length information to provide more efficient implementations. Evaluating these methods turns up with about 5-6% of akka-http message parsing.
43f194d
to
40f0514
Compare
I basically just saw these turning up in play / akka-http benchmarks. It seems one reason that I saw For the |
I searched a bit before but couldn't find it |
Was it this one? It's a JDK patch by Jason, but it's about forwarders not https://gist.github.com/retronym/d27090a68570485c3e329a52db0c7b25 |
Interesting information. FWIW, in this case, methods from |
My JDK patch was intended to make the extra indirection of the trait encoding "invisible" to the inliner heuristics. I've been meaning to get back to it, but I haven't been able to get my dev environment setup for OpenJDK builds recently :( |
I'm seeing a 6% improvement to the performance of our compiler benchmark suite with Related discussion on SO: Why does the JVM has a max inline depth? It will be interesting to see how much of that improvement I could get under the default limit with my JDK patch applied. |
@lrytz - Yes, this patch looks sensible to me too. |
Uses the extra length information in comparison to list to provide efficient implementations.
Evaluating these three methods turns up with about 6-7% of akka-http message parsing.
From the profiles it looks the likely reason are polymorphic invokeinterface calls against List (i.e. just forwarding to
start.isEmpty
etc wouldn't help).