Skip to content
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

PERFORMANCE: Lucene.Net.Replicator.LocalReplicator::CheckExpiredSessions(): Remove unnecessary dictionary allocation #1070

Open
1 task done
NightOwl888 opened this issue Dec 19, 2024 · 0 comments
Labels
good-first-issue Good for newcomers is:task A chore to be done performance pri:normal up-for-grabs This issue is open to be worked on by anyone

Comments

@NightOwl888
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Task description

In Lucene.Net.Replicator.LocalReplicator::CheckExpiredSessions(), there is an extra .ToArray() call that allocates a new collection to iterate the Values:

private readonly IDictionary<string, ReplicationSession> sessions = new Dictionary<string, ReplicationSession>();
/// <exception cref="InvalidOperationException"></exception>
private void CheckExpiredSessions()
{
// .NET NOTE: .ToArray() so we don't modify a collection we are enumerating...
// I am wondering if it would be overall more practical to switch to a concurrent dictionary...
foreach (ReplicationSession token in sessions.Values.Where(token => token.IsExpired(ExpirationThreshold)).ToArray())
{
ReleaseSession(token.Session.Id);
}
}

J2N 2.1 includes the update to J2N.Collections.Generic.Dictionary<TKey, TValue> that allows deleting while iterating forward through the collection in older target frameworks. So, swapping the implementation of the sessions field will allow us to remove this extra allocation.

@NightOwl888 NightOwl888 added performance up-for-grabs This issue is open to be worked on by anyone good-first-issue Good for newcomers pri:normal is:task A chore to be done labels Dec 19, 2024
@NightOwl888 NightOwl888 added this to the 4.8.0-beta00018 milestone Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for newcomers is:task A chore to be done performance pri:normal up-for-grabs This issue is open to be worked on by anyone
Projects
None yet
Development

No branches or pull requests

1 participant