Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3893

Significant allocations from unnecessary lambda capture on deserialization path

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • csharp

    Description

      During investigation of a GC issue in a C# project we discovered that ~10% of allocations 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:

       

      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));
              }
      
              ....
       

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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jbit84 Jannick Bitsch
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m