Skip to content

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

Closed

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

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 28, 2022
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on May 12, 2022
  3. added this to the 8.0.0 milestone on Aug 22, 2022
  4. modified the milestones: 8.0.0, 9.0.0 on May 23, 2024
  5. modified the milestones: 9.0.0, 10.0.0 on Dec 9, 2024
  6. modified the milestones: 10.0.0, 11.0.0 on Aug 12, 2025
  7. added
    in-prThere is an active PR which will close this issue when it is merged
    on May 22, 2026
  8. modified the milestones: 11.0.0, 12.0.0 on Jun 30, 2026
  9. added a commit that references this issue on Aug 14, 2026
    bbee85f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-Serializationin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions