-
Couldn't load subscription status.
- Fork 1.4k
Bring back the addMetrics optimization of LinkedQueue to improve performances of Queue.unbounded
#9762
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
faa2fea to
eb77066
Compare
eb77066 to
7745a99
Compare
| override def size(): Int = jucConcurrentQueue.size() | ||
|
|
||
| override def enqueuedCount(): Long = enqueuedCounter.get() | ||
| override def enqueuedCount(): Long = if (addMetrics) enqueuedCounter.get() else 0L |
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.
I guess this is very minor, but in order to avoid adding addMetrics as a class field, you could do this instead (and everywhere else I guess):
| override def enqueuedCount(): Long = if (addMetrics) enqueuedCounter.get() else 0L | |
| override def enqueuedCount(): Long = if (enqueuedCounter ne null) enqueuedCounter.get() else 0L |
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.
Done
0c7ec98 to
a9b9edd
Compare
| */ | ||
| private[this] val enqueuedCounter = new AtomicLong(0) | ||
| private[this] val dequeuedCounter = new AtomicLong(0) | ||
| private[this] val enqueuedCounter = if (addMetrics) new AtomicLong(0) else null |
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.
@kyri-petrou Do you know why we need private[this] and not just private? 🤔
private[this] is something dropped from Scala3 anyway: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html#
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.
The code compiles differently between Scala 2/3. In Scala 2 the compiler will generate a private accessor method when you use private but not when you use private[this]. Basically private[this] in Scala 2 compiles the same way as private in Scala 3
See also:
FYI @ghostdogpr