[ https://issues.apache.org/jira/browse/HIVE-5019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14028555#comment-14028555 ]
Thejas M Nair commented on HIVE-5019: ------------------------------------- In the following change, there is a bug. The tmp needs to get 'reset' after the toString(). Not sure what the most efficient way to do that is (delete vs new StringBuilder). {code} + StringBuilder tmp = new StringBuilder(""); for (String key : properties.keySet()) { if (properties.get(key) != null && !duplicateProps.contains(key)) { - realProps.add(" '" + key + "'='" + - escapeHiveCommand(StringEscapeUtils.escapeJava(properties.get(key))) + "'"); + tmp.append(" '"); + tmp.append(key); + tmp.append("'='"); + tmp.append(escapeHiveCommand(StringEscapeUtils.escapeJava(properties.get(key)))); + tmp.append("'"); + realProps.add(tmp.toString()); } {code} This does make the code more verbose and less readable. I am not very convinced that in cases like the one above, the use of StringBuilder would make a difference. The compiler would usually replace + with use of StringBuilder in simple cases like this. bq. Yes, they do mostly replace + with StringBuilder.append(). However this is not always the case it seems. I ran some tests and they showed that using the StringBuilder when appending strings is 57% faster than using the + operator (using the StringBuffer took 122 milliseconds whilst the + operator took 284 milliseconds). Can you please upload the test code you used ? Can you try running it longer (say more than 5-10 seconds), so any noise is filtered out. > Use StringBuffer instead of += (issue 1) > ---------------------------------------- > > Key: HIVE-5019 > URL: https://issues.apache.org/jira/browse/HIVE-5019 > Project: Hive > Issue Type: Sub-task > Reporter: Benjamin Jakobus > Assignee: Benjamin Jakobus > Attachments: HIVE-5019.2.patch.txt, HIVE-5019.3.patch.txt > > > Issue 1 - use of StringBuilder over += inside loops. > java/org/apache/hadoop/hive/ql/optimizer/physical/GenMRSkewJoinProcessor.java > java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java > java/org/apache/hadoop/hive/ql/parse/PTFTranslator.java > java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java > java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java > java/org/apache/hadoop/hive/ql/plan/ConditionalResolverMergeFiles.java > java/org/apache/hadoop/hive/ql/plan/PlanUtils.java > java/org/apache/hadoop/hive/ql/security/authorization/BitSetCheckedAuthorizationProvider.java > java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsUtils.java > java/org/apache/hadoop/hive/ql/udf/UDFLike.java > java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSentences.java > java/org/apache/hadoop/hive/ql/udf/generic/NumDistinctValueEstimator.java > java/org/apache/hadoop/hive/ql/udf/ptf/NPath.java -- This message was sent by Atlassian JIRA (v6.2#6252)