[
https://issues.apache.org/jira/browse/CALCITE-3878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17068950#comment-17068950
]
Vladimir Sitnikov edited comment on CALCITE-3878 at 3/27/20, 6:07 PM:
----------------------------------------------------------------------
How about replacing:
{noformat}
public List<RexNode> rexArguments() {
List<RelDataTypeField> inputTypes =
inputPhysType.getRowType().getFieldList();
List<RexNode> args = new ArrayList<>();
for (int index : agg.call.getArgList()) {
args.add(RexInputRef.of(index, inputTypes));
}
return args;
}
{noformat}
with
{noformat}
fun rexArguments(): List<RexNode> {
val inputTypes = inputPhysType.getRowType().getFieldList()
return agg.call.getArgList().map {
RexInputRef.of(it, inputTypes)
}
}
{noformat}
?
PS. I think I understand what you mean, however, the PR is quite small +34-28,
and it is an obvious win. Of course, it adds code, and it makes it slightly
less easy to follow, however, I think it is a positive net change.
Note: you are right the hotspots will show in the profiling, however:
1) Noone profiles Calcite. Is there a solid benchmark and/or continuous effort
to run benchmarks and profile it?
2) The absence of initial size is often very puzzling when one reads the code.
For instance, one might wonder if the initial size should be added or not,
however, one can't tell if the code is hot or not by merely reading the code.
For instance, SqlTypeUtil#deriveAndCollectTypes sounds like one of the possible
hot methods for me.
3) We do have bug reports with extremely deep OR hierarchies. The same might
easily go for a huge number of selected expressions (e.g. SQL that projects
1000 expressions). So changes like {{new ArrayList<>(projs.size());}} might
easily be helpful.
PPS. It is really sad we spend time on discussing this. I think everybody here
agrees we are going to refuse trivial fixes like {{append(" ")}} => {{append('
')}}, however, the improvement of this PR is way more significant than changing
double-quotes with single-quotes.
was (Author: vladimirsitnikov):
How about replacing:
{noformat}
public List<RexNode> rexArguments() {
List<RelDataTypeField> inputTypes =
inputPhysType.getRowType().getFieldList();
List<RexNode> args = new ArrayList<>();
for (int index : agg.call.getArgList()) {
args.add(RexInputRef.of(index, inputTypes));
}
return args;
}
{noformat}
with
{noformat}
fun rexArguments(): List<RexNode> {
val inputTypes = inputPhysType.getRowType().getFieldList()
return agg.call.getArgList().map { RexInputRef.of(it, inputTypes)
}
}
{noformat}
?
PS. I think I understand what you mean, however, the PR is quite small +34-28,
and it is an obvious win. Of course, it adds code, and it makes it slightly
less easy to follow, however, I think it is a positive net change.
Note: you are right the hotspots will show in the profiling, however:
1) Noone profiles Calcite. Is there a solid benchmark and/or continuous effort
to run benchmarks and profile it?
2) The absence of initial size is often very puzzling when one reads the code.
For instance, one might wonder if the initial size should be added or not,
however, one can't tell if the code is hot or not by merely reading the code.
For instance, SqlTypeUtil#deriveAndCollectTypes sounds like one of the possible
hot methods for me.
3) We do have bug reports with extremely deep OR hierarchies. The same might
easily go for a huge number of selected expressions (e.g. SQL that projects
1000 expressions). So changes like {{new ArrayList<>(projs.size());}} might
easily be helpful.
PPS. It is really sad we spend time on discussing this. I think everybody here
agrees we are going to refuse trivial fixes like {{append(" ")}} => {{append('
')}}, however, the improvement of this PR is way more significant than changing
double-quotes with single-quotes.
> Make ArrayList creation with initial capacity when size is fixed
> ----------------------------------------------------------------
>
> Key: CALCITE-3878
> URL: https://issues.apache.org/jira/browse/CALCITE-3878
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.22.0
> Reporter: neoremind
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> I find many places in Calcite where _new ArrayList<>()_ is used, if the list
> is expected to be immutable or not resizing, it is always a good manner to
> create with initial capacity, better for memory usage and performance.
> I search all occurrences, focus on the core module, to make it safe, I only
> update local variables with fixed size and not working in recursive method.
> If the local variable reference goes out of scope, if resizing is needed,
> things will work normally as well, so no side effect, but for the "escaping"
> case, I am very conservative and do not change them.
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)