-
Notifications
You must be signed in to change notification settings - Fork 641
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
Lucene.Net.Replicator.LocalReplicator.ReplicationSession: Removed unnecessary array allocation #1108
Conversation
…: Use J2N.Collections.Dictionary<TKey, TValue> to allow deleting while iterating forward prior to .NET Core (fixes apache#1070).
Interesting results, just scratching the surface hints that the J2N implementation is actually worse performance wise on .NET Framework where on .NET core it's much more close, the extra allocation are shown but MS is clearly improving this (from nearly 40 bytes to just nearly 15 bytes between .NET 8 and 9).
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
BenchmarkRunner.Run<DictionaryBenchmarks>();
[MemoryDiagnoser]
public class DictionaryBenchmarks
{
[Benchmark]
public byte BuiltInDictionary()
{
Dictionary<string, string> values = new ();
AddItems(values);
foreach (string b in values.Values.Where(x => x.Length > 1).ToArray())
values.Remove(b);
return 1;
}
[Benchmark]
public int J2NDictionary()
{
J2N.Collections.Generic.Dictionary<string, string> values = new();
AddItems(values);
foreach (string b in values.Values.Where(x => x.Length > 1))
values.Remove(b);
return 1;
}
private void AddItems(IDictionary<string,string> x)
{
x.Add("00", "00");
x.Add("01", "01");
x.Add("02", "02");
x.Add("03", "03");
x.Add("04", "04");
x.Add("05", "05");
x.Add("06", "06");
x.Add("07", "07");
x.Add("08", "08");
x.Add("09", "09");
x.Add("10", "10");
x.Add("11", "11");
x.Add("12", "12");
x.Add("13", "13");
x.Add("14", "14");
x.Add("15", "15");
}
} One overall concern I would have when switching from the core implementation of collections to a custom one (from e.g. J2N) is that Microsoft is pushing on performance with every itteration of .NET while other implementations might not keep up. |
A few things to note:
That being said, perhaps it would be worth it to review the changes to the dictionary in .NET 9 to see whether it makes sense to do another dictionary upgrade in J2N. |
|
.NET FrameworkThere is one other difference that could explain what you are seeing on .NET Framework. We patched the implementation to nullify the data buckets only for reference types, whereas .NET Framework did it for both value and reference types. There is a method called So, 2 ways we could deal with this:
.NET 9 ImplementationActually, it is possible that the difference between |
Ohhh... My sincere appologies... Now i get the issue here (the title could be more clear though as I think this is a more important focus). WTF... I did not know there was a difference in how "Remove" was implemented in .NET 8/9 vs Framework, thats a contract change between the versions i did not know of and is quite problematic in terms of the NETStandard promise o.O, yikes. I basically looked at this from a "performance optimization" perspective, and went, "but is it really an improvement". The functional part is way more important IMO. As a side note, all this talk about dropping .NET Framework support (or NETStandard 2.0) is not something I am truely fond of as someone who uses it from that stack still, and I currently don't know if we will manage to actually upgrade within the comming years. :(... So hopefully that will be for a Lucene 10.X (or which Java version is the next target) and not 4.8 final release thing >.<... |
Lucene.Net.Replicator.LocalReplicator.ReplicationSession: Removed unnecessary array allocation
Fixes #1070
Description
This changes
ReplicationSession.sessions
to useJ2N.Collections.Dictionary<TKey, TValue>
which allows deleting while iterating forward prior to .NET Core. This removes a.ToArray()
allocation just for the sake of using an enumerator to clean up replication sessions.