Skip to content

[SPARK-23960][SQL][MINOR] Mark HashAggregateExec.bufVars as transient #21039

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -174,8 +174,8 @@ case class HashAggregateExec(
}
}

// The variables used as aggregation buffer. Only used for aggregation without keys.
private var bufVars: Seq[ExprCode] = _
// The variables used as aggregation buffer. Only used in codegen for aggregation without keys.
@transient private var bufVars: Seq[ExprCode] = _

private def doProduceWithoutKeys(ctx: CodegenContext): String = {
val initAgg = ctx.addMutableState(CodeGenerator.JAVA_BOOLEAN, "initAgg")
Expand Down Expand Up @@ -236,6 +236,8 @@ case class HashAggregateExec(
| }
""".stripMargin)

bufVars = null // explicitly null this field out to allow the referent to be GC'd sooner
Copy link
Member

@kiszk kiszk Apr 11, 2018

Choose a reason for hiding this comment

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

I am curious what happens when bufVars is accessed in doConsumeWithoutKeys where exists below this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The workflow of whole-stage codegen ensures that doConsumeWithoutKeys can only be on the call stack when doProduceWithoutKeys is also on the call stack; the liveness of the former is strictly a subset of the latter.
That's because for a plan tree that looks like:

+- A
  +- B
    +- C

The whole-stage codegen system (mostly) works like:

A.produce
 |------> B.produce
 |         |------> C.produce
 |         |         |------> B.consume
 |         |         |         |------> A.consume
 |         |         |         |        |
 |         |         |         |<-------o
 |         |         |<--------o
 |         |<--------o
 |<--------o
 o

Copy link
Member

Choose a reason for hiding this comment

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

Ah, got it. Thank you for the clarification.


val numOutput = metricTerm(ctx, "numOutputRows")
val aggTime = metricTerm(ctx, "aggTime")
val beforeAgg = ctx.freshName("beforeAgg")
Expand Down