-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SortedList performance #112123
Comments
Tagging subscribers to this area: @dotnet/area-system-collections |
The performance measurement is not in a correct way. .NET Core employs more optimizations than .NET Framework, and requires much more loops to achieve a steady state performance. Using With a proper benchmark set up on Windows like this: [SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.Net90)]
public class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<Program>();
}
private SortedList<int, string> originalSortedList;
[GlobalSetup]
public void Setup()
{
originalSortedList = new SortedList<int, string>();
for (int j = 0; j < 1000; j++)
{
var newDate = DateTime.Today.AddDays(j);
originalSortedList.Add(j, j.ToString());
}
}
[Benchmark]
public SortedList<int, string> Copy() => new SortedList<int, string>(originalSortedList);
} The result shows better performance on .NET 9:
Even when running your original code on Windows x64, I'm only seeing an 2x performance difference during startup stage. |
Description
I am currently migrating my Xamarin.iOS app to .Net for iOS. During testing of this we noticed a performance hit when loading data. Drilling into this we noticed that it was coming from doing a deep copy of SortedLists.
What we do is copy one SortedList to another via its constructor (https://learn.microsoft.com/en-us/dotnet/api/system.collections.sortedlist.-ctor?view=net-9.0#system-collections-sortedlist-ctor(system-collections-idictionary)).
While this does create a deep copy of the SortedList it is significantly slower than it was in our old Xamarin App.
I have created 2 dummy projects to investigate, one in .Net Framework 4.8 and another in .Net 8.
Both are console apps that create a SortedList<Datetime, string> with 1000 dates, then measures the ticks it takes to copy this to a new SortedList. I run this 100 times to get an average.
Here is the example code I used in both the .Net Framework 4.8 and .Net 8 versions.
Are the default comparers slower in the .Net 8 and later versions than they previously were or are there other operations going on that previously weren't?
Are there any reasons why the performance has changed so much and is there any way we can get it performing as well as it previously did?
Configuration
The code is running on both .Net Framework 4.8 and .Net 8 for comparison.
I am running a MacBook Pro M1 Max, which will have an ARM64 architecture.
Current OS version is macOS Sonoma 14.6.1.
This is also being experienced on a number of iPads.
Regression?
The code is running on both .Net Framework 4.8 and .Net 8 for comparison.
Data
Below is the data from a run of both versions
The text was updated successfully, but these errors were encountered: