Bring back the addMetrics optimization of LinkedQueue to improve performances of Queue.unbounded#9762
Merged
guizmaii merged 2 commits intoseries/2.xfrom Apr 9, 2025
Merged
Conversation
faa2fea to
eb77066
Compare
eb77066 to
7745a99
Compare
kyri-petrou
reviewed
Apr 8, 2025
| override def size(): Int = jucConcurrentQueue.size() | ||
|
|
||
| override def enqueuedCount(): Long = enqueuedCounter.get() | ||
| override def enqueuedCount(): Long = if (addMetrics) enqueuedCounter.get() else 0L |
Contributor
There was a problem hiding this comment.
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):
Suggested change
| override def enqueuedCount(): Long = if (addMetrics) enqueuedCounter.get() else 0L | |
| override def enqueuedCount(): Long = if (enqueuedCounter ne null) enqueuedCounter.get() else 0L |
0c7ec98 to
a9b9edd
Compare
guizmaii
commented
Apr 9, 2025
| */ | ||
| 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 |
Member
Author
There was a problem hiding this comment.
@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#
Contributor
There was a problem hiding this comment.
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
kyri-petrou
approved these changes
Apr 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See also:
FYI @ghostdogpr