You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Christophe Le Saec (Jira)" <ji...@apache.org> on 2023/07/26 15:23:00 UTC

[jira] [Commented] (AVRO-2731) Avro should not use new HashMap(targetSize) in generated code for records

    [ https://issues.apache.org/jira/browse/AVRO-2731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17747569#comment-17747569 ] 

Christophe Le Saec commented on AVRO-2731:
------------------------------------------

What do you think to replace it with 
{code:java}
m${nv} = new java.util.HashMap<${kt},${vt}>((int)(size${nv} * 4)/3 + 1);
{code}
?
(considering the loadFactor default is 3/4)

> Avro should not use new HashMap(targetSize) in generated code for records
> -------------------------------------------------------------------------
>
>                 Key: AVRO-2731
>                 URL: https://issues.apache.org/jira/browse/AVRO-2731
>             Project: Apache Avro
>          Issue Type: Improvement
>            Reporter: Roman Leventov
>            Priority: Major
>
> [https://github.com/apache/avro/blob/4a1e3acdc09de0545cbb6bfd4554604e64ca1a35/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm#L808]
> This is improper usage of HashMap constructor. See Guava's [Maps.newHashMapWithExpectedSize|[https://github.com/google/guava/blob/6e0c5b5d50a3e457ae0d787f7c9be7b48c10120b/guava/src/com/google/common/collect/Maps.java#L306-L337]] code for details.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)