[ https://issues.apache.org/jira/browse/CALCITE-3878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17069000#comment-17069000 ]
Julian Hyde commented on CALCITE-3878: -------------------------------------- I wish we didn't have to spend time on this, too. Believe, me I have better things. The following code is not an improvement: {code:java} @Override public RelNode convert(RelNode rel) { LogicalJoin join = (LogicalJoin) rel; List<RelNode> newInputs = new ArrayList<>(join.getInputs().size()); for (RelNode input : join.getInputs()) { {code} because joins have only 2 inputs. bq. Note: you are right the hotspots will show in the profiling, however: 1) Noone profiles Calcite The principle is that that code is not performance critical unless proven otherwise. In 98% of our code, clarity is more important than performance. By accepting this fix, we are accepting the principle that {{new ArrayList()}} without a size is wrong. It is not wrong. We are writing in a high-level language. I do agree with you that a modern 'functional' style can be clear, non-redundant and performant. > 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)