Skip to content
Closed
Show file tree
Hide file tree
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 @@ -255,11 +255,12 @@ private[sql] case class DataSourceScan(
| $numOutputRows.add(numRows);
| }
|
| while (!shouldStop() && $idx < numRows) {
| // this loop is very perf sensitive and changes to it should be measured carefully
| while ($idx < numRows) {
| int $rowidx = $idx++;
| ${consume(ctx, columns1).trim}
| if (shouldStop()) return;
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 add some comment somewhere to explain why shouldStop needs to be here? It'd be great to reference the JIRA ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's here in the beginning.

Copy link
Contributor

Choose a reason for hiding this comment

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

where is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

btw i'm not sure but i suspect this has to do with loop unrolling. jit stops unrolling the loop when shouldStop is part of the terminal condition.

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 add a comment around line 248 saying this loop is very perf sensitive and changes to it should be measured carefully?

| }
| if (shouldStop()) return;
|
| if (!$input.hasNext()) {
| $batch = null;
Expand All @@ -280,14 +281,15 @@ private[sql] case class DataSourceScan(
s"""
| private void $scanRows(InternalRow $row) throws java.io.IOException {
| boolean firstRow = true;
| while (!shouldStop() && (firstRow || $input.hasNext())) {
| while (firstRow || $input.hasNext()) {
| if (firstRow) {
| firstRow = false;
| } else {
| $row = (InternalRow) $input.next();
| }
| $numOutputRows.add(1);
| ${consume(ctx, columns2, inputRow).trim}
| if (shouldStop()) return;
| }
| }""".stripMargin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ trait CodegenSupport extends SparkPlan {
* # call child.produce()
* initialized = true;
* }
* while (!shouldStop() && hashmap.hasNext()) {
* while (hashmap.hasNext()) {
* row = hashmap.next();
* # build the aggregation results
* # create variables for results
* # call consume(), which will call parent.doConsume()
* if (shouldStop()) return;
* }
*/
protected def doProduce(ctx: CodegenContext): String
Expand Down Expand Up @@ -252,9 +253,10 @@ case class InputAdapter(child: SparkPlan) extends UnaryNode with CodegenSupport
ctx.currentVars = null
val columns = exprs.map(_.gen(ctx))
s"""
| while (!shouldStop() && $input.hasNext()) {
| while ($input.hasNext()) {
| InternalRow $row = (InternalRow) $input.next();
| ${consume(ctx, columns, row).trim}
| if (shouldStop()) return;
| }
""".stripMargin
}
Expand Down Expand Up @@ -321,7 +323,7 @@ case class WholeStageCodegen(child: SparkPlan) extends UnaryNode with CodegenSup
/** Codegened pipeline for:
* ${toCommentSafeString(child.treeString.trim)}
*/
class GeneratedIterator extends org.apache.spark.sql.execution.BufferedRowIterator {
final class GeneratedIterator extends org.apache.spark.sql.execution.BufferedRowIterator {

private Object[] references;
${ctx.declareMutableStates()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ case class Range(
| }
| }
|
| while (!$overflow && $checkEnd && !shouldStop()) {
| while (!$overflow && $checkEnd) {
| long $value = $number;
| $number += ${step}L;
| if ($number < $value ^ ${step}L < 0) {
| $overflow = true;
| }
| ${consume(ctx, Seq(ev))}
| if (shouldStop()) return;
| }
""".stripMargin
}
Expand Down