Skip to content

[Xml serialization]ReflectionXmlSerializationWriter is using Array.GetValue method for primary type arrays #67221

@TrayanZapryanov

Description

@TrayanZapryanov

When serializing arrays of primary type I've found a code which fallbacks to Array.GetValue in ReflectionXmlSerializationWriter .WriteArrayItems method. Code:

 var arr = o as IList;

  if (arr != null)
  {
      for (int i = 0; i < arr.Count; i++)
      {
          object? ai = arr[i];
          WriteElements(ai, null/*choiceName + "i"*/, elements, text, choice, true, true);
      }
  }

This results in a lot of allocations in simple serialization loop program.
image

This is not a real issue found in production code - just something that popups while trying to optimize the upper allocation :
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions