[
https://issues.apache.org/jira/browse/AVRO-3721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17698410#comment-17698410
]
Christophe Le Saec commented on AVRO-3721:
------------------------------------------
Indeed, it would be change API for this class, not good for compatibility.
In avro code, this method is only used by ReflectData
{code:java}
recordField.getObjectProps().containsKey
{code}
And by SpecificCompiler
{code:java}
for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) {
newP.addProp(a.getKey(), a.getValue());
}
{code}
So, if we add methods :
{code:java}
public boolean containsKey(String k) { ... }
public void forEach(BiConsumer<String, Object> consumer) { ... }
{code}
And may be few others if needed (like Iterator<String> getKeys()), we could
avoid usage of this function.
WDYT ? ( i will build PR for this)
> [Java] Add cache to org.apache.avro.JsonProperties.getObjectProps
> -----------------------------------------------------------------
>
> Key: AVRO-3721
> URL: https://issues.apache.org/jira/browse/AVRO-3721
> Project: Apache Avro
> Issue Type: Improvement
> Components: java
> Affects Versions: 1.11.1
> Reporter: Moshe Elisha
> Priority: Minor
>
> Currently every time you invoke JsonProperties.getObjectProps on same
> instance, the code loops over the props and creates a new LinkedHashMap and a
> new UnmodifiableMap.
>
> In our use case, we store a Protocol (and the JsonProperties) and access the
> same instances multiple times.
>
> Storing a simple cache "private Map<String, Object> objectProps;" inside
> JsonProperties will slightly improve performance and memory usage.
> objectProps can be lazy initialized in JsonProperties.getObjectProps and
> reset when "JsonProperties.addProp(String, JsonNode)" is invoked.
>
> Thanks.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)