Skip to content

Commit

Permalink
SWEEP: Removed FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION. Updated…
Browse files Browse the repository at this point in the history
… private fields to use J2N.Collections.Generic.Dictionary<TKey,TValue> for a performance boost when we upgrade to J2N 3.x (GetEnumerator() currently boxes from struct to interface). (fixes #978)
  • Loading branch information
NightOwl888 committed Oct 21, 2024
1 parent 2373399 commit ce1c722
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
1 change: 0 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp3.')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) Or $(TargetFramework.StartsWith('net7.')) Or $(TargetFramework.StartsWith('net8.')) ">

<DefineConstants>$(DefineConstants);FEATURE_ARGITERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_PROCESS_KILL_ENTIREPROCESSTREE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_STRING_CONCAT_READONLYSPAN</DefineConstants>

Expand Down
11 changes: 3 additions & 8 deletions src/Lucene.Net.Facet/Taxonomy/WriterCache/NameIntCacheLRU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using JCG = J2N.Collections.Generic;

namespace Lucene.Net.Facet.Taxonomy.WriterCache
{
Expand Down Expand Up @@ -162,13 +163,7 @@ private void CreateCache(int maxSize)
}
else
{
#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION
cache = new Dictionary<TName, int>(capacity: 1000);
#else
// LUCENENET specific - we use ConcurrentDictionary here because it supports deleting while
// iterating through the collection, but Dictionary does not.
cache = new ConcurrentDictionary<TName, int>(concurrencyLevel: 3, capacity: 1000); //no need for LRU
#endif
cache = new JCG.Dictionary<TName, int>(capacity: 1000);
}
}

Expand Down Expand Up @@ -255,4 +250,4 @@ bool IInternalNameInt32CacheLru.MakeRoomLRU()
return true;
}
}
}
}
14 changes: 5 additions & 9 deletions src/Lucene.Net.TestFramework/Util/Fst/FSTTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,9 @@ private void VerifyPruned(int inputMode, FST<T> fst, int prune1, int prune2)

// build all prefixes

#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION
IDictionary<Int32sRef, CountMinOutput<T>> prefixes = new Dictionary<Int32sRef, CountMinOutput<T>>();
#else
// LUCENENET: We use ConcurrentDictionary<TKey, TValue> because Dictionary<TKey, TValue> doesn't support
// deletion while iterating, but ConcurrentDictionary does.
IDictionary<Int32sRef, CountMinOutput<T>> prefixes = new ConcurrentDictionary<Int32sRef, CountMinOutput<T>>();
#endif
// LUCENENET specific - using concrete type for the readerMap field, since it will eliminate boxing to an interface on GetEnumerator() calls
JCG.Dictionary<Int32sRef, CountMinOutput<T>> prefixes = new JCG.Dictionary<Int32sRef, CountMinOutput<T>>();

Int32sRef scratch = new Int32sRef(10);
foreach (InputOutput<T> pair in pairs)
{
Expand Down Expand Up @@ -927,7 +923,7 @@ private void VerifyPruned(int inputMode, FST<T> fst, int prune1, int prune2)
if (!keep)
{
//it.remove();
prefixes.Remove(ent);
prefixes.Remove(prefix);
//System.out.println(" remove");
}
else
Expand Down Expand Up @@ -1028,4 +1024,4 @@ private void VerifyPruned(int inputMode, FST<T> fst, int prune1, int prune2)
}
}
}
}
}
9 changes: 2 additions & 7 deletions src/Lucene.Net/Index/IndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,8 @@ public ReaderPool(IndexWriter outerInstance)
this.outerInstance = outerInstance;
}

#if FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION
private readonly IDictionary<SegmentCommitInfo, ReadersAndUpdates> readerMap = new Dictionary<SegmentCommitInfo, ReadersAndUpdates>();
#else
// LUCENENET: We use ConcurrentDictionary<TKey, TValue> because Dictionary<TKey, TValue> doesn't support
// deletion while iterating, but ConcurrentDictionary does.
private readonly IDictionary<SegmentCommitInfo, ReadersAndUpdates> readerMap = new ConcurrentDictionary<SegmentCommitInfo, ReadersAndUpdates>();
#endif
// LUCENENET specific - using concrete type for the readerMap field, since it will eliminate boxing to an interface on GetEnumerator() calls
private readonly JCG.Dictionary<SegmentCommitInfo, ReadersAndUpdates> readerMap = new JCG.Dictionary<SegmentCommitInfo, ReadersAndUpdates>();

// used only by asserts
public virtual bool InfoIsLive(SegmentCommitInfo info)
Expand Down

0 comments on commit ce1c722

Please sign in to comment.