Skip to content

[iOS] .NET 9 System.Xml significant performance drop compared to .NET 8 #119580

@jurganson

Description

@jurganson

Description

Having an app that runs large amount of data through a XML ToString(), using the System.XML, performs very poorly in .NET 9 iOS, compared to .NET 8

In the reproduction repo(s) I have set up a simple UI with a spinner animation and a list that can be scrolled. When pressing the button, 40000 entries are serialized to XML using the following code:

var xmlResults = _xmlTestData.Select(x => x.Serialize()).ToList();

where Serialize() is implemented like:

using (var sw = new StringWriter())
{
	var settings = new XmlWriterSettings { CheckCharacters = false };
	using (var xw = XmlWriter.Create(sw, settings))
		xe.WriteTo(xw);
	return sw.ToString();
}

The results shows a general impact on performance running both release and debug, however a very big gap between .NET 9 and 8 in release mode on iOS. There seems to be no performance gain in release mode from debug on .NET 9.

Furthermore, the UI thread is heavily impacted. In the repro you can start the background work and try to scroll the included list, which will lag a lot. This is not the same behavior on .NET 8, where the UI thread is able to scroll smoothly as well.

All images below are from the reproduction apps, linked below:

Image

Tested on a iPhone 15 Pro Max

For comparison, here is the same results, comparing Android:

Image

Tested on an Samsung Galaxy S23

In Android we see consistent results across both .NET versions, in debug and release.

Both reproduction apps in .NET 8 and 9 can be picked up here, where the only difference is the target .NET version:
.NET 9 repo
.NET 8 repo

Steps to Reproduce

  • Run the repo apps on an iOS device in release mode.
  • See the significant difference in general UI thread performance and resulting time performance.
  • Scroll the list for extra jitters.

Link to public reproduction project repository

No response

Version with bug

9.0.100 SR10

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

.NET 8 (Please specify exact version)

Affected platforms

iOS

Affected platform versions

iOS 15 and up

Did you find any workaround?

Not at the moment no.

Trying to create a simple DIY XML serializer, yielding a lot better results, however questionable for a production build.

One experiment that seemed to work rather well was to introduce a batched .Select, which would call .Select(x => x.Serialize) in a batched loop (with a batch size of about 200 yielding the best result) but most importantly, with a Thread.Sleep(2) between batches.

Relevant log output

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions