Skip to content
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

=str Make decider caculation lazy #627

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ private[stream] object Collect {

def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler {
val decider = inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider
lazy val decider = inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider

private var aggregator: Out = zero
private var aggregating: Future[Out] = Future.successful(aggregator)
Expand Down Expand Up @@ -1402,8 +1402,7 @@ private[stream] object Collect {
new GraphStageLogic(shape) with InHandler with OutHandler {
override def toString = s"MapAsyncUnordered.Logic(inFlight=$inFlight, buffer=$buffer)"

private val decider =
inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider
private lazy val decider = inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a def? In most places in this source file, this is a def.

The def means no synchronize block. lazy vals come with the overhead of having synchronize in the generated byte code.

Copy link
Member Author

@He-Pin He-Pin Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. def will do recaculation, and that should be avoid.
  2. lazy val will only do synchronization the first time, and the supervision strategy method is expected to be quick for calculation, so even the undering Thread is a VirtualThread, it will not cause any problem either.


private var inFlight = 0
private var buffer: BufferImpl[Out] = _
Expand Down
Loading