Jannick Bitsch created AVRO-3893:
------------------------------------

             Summary: Significant allocations from unnecessary lambda capture 
on deserialization path
                 Key: AVRO-3893
                 URL: https://issues.apache.org/jira/browse/AVRO-3893
             Project: Apache Avro
          Issue Type: Improvement
          Components: csharp
            Reporter: Jannick Bitsch


During investigation of a GC issue of a C# project we discovered that ~10% 
could be attributed to an unnecessary lambda capture on a hot-path of Avro 
deserialization while utilizing a PreresolvingDatumReader. 

 

The capture happens in ObjectCreator.FindType where, instead of using the 'key' 
parameter passed to the value function, the lambda captures the 'name' method 
parameter:

 
{code:java}
private Type FindType(string name)
{
    return typeCacheByName.GetOrAdd(name, (_) =>
    {
        Type type = null;

        if (TryGetIListItemTypeName(name, out var itemTypeName))
        {
            return GenericIListType.MakeGenericType(FindType(itemTypeName));
        }

        if (TryGetNullableItemTypeName(name, out itemTypeName))
        {
            return GenericNullableType.MakeGenericType(FindType(itemTypeName));
        }

        ....
 {code}
It should be a simple improvement to use the value passed to the Func<string, 
Type> instead. Will open a PR. 



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

Reply via email to