[
https://issues.apache.org/jira/browse/LUCENENET-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16902578#comment-16902578
]
Shad Storhaug commented on LUCENENET-602:
-----------------------------------------
Come to think of it, the primary reason why LurchTable was chosen was not for
thread safety, but for performance (it's all coming back to me
now)....[https://apache.markmail.org/search/?q=lucenenet+lurchtable#query:lucenenet%20lurchtable+page:1+mid:wtuyqd3sfre6532s+state:results|https://apache.markmail.org/search/?q=lucenenet+lurchtable#query:lucenenet%20lurchtable+page:1+mid:wtuyqd3sfre6532s+state:results].
We had another implementation previously that looks a lot like the one you
linked to (with lots of lock statements) and we had some complaints about how
it performed. I would rather try to fix it so it works with Xamarin.iOS than to
replace it, if possible.
{quote}At the link
[https://docs.microsoft.com/it-it/xamarin/ios/internals/limitations] , I found
the problem cause (I suppose...):
{quote}
{quote}Value types as Dictionary Keys Using a value type as a Dictionary<TKey,
TValue> key is problematic, as the default Dictionary constructor attempts to
use EqualityComparer<TKey>.Default. EqualityComparer<TKey>.Default, in turn,
attempts to use Reflection to instantiate a new type which implements the
IEqualityComparer<TKey> interface. This works for reference types (as the
reflection+create a new type step is skipped), but for value types it crashes
and burns rather quickly once you attempt to use it on the device. Workaround:
Manually implement the IEqualityComparer<TKey> interface in a new type and
provide an instance of that type to the Dictionary<TKey, TValue>
(IEqualityComparer<TKey>) constructor.
{quote}
Just out of curiosity, what happens if you provide a custom EqualityComparer
instead of falling back to {{EqualityComparer<TKey>.Default}}? Do note that
LurchTable seems to have many hard coded references to
{{EqualityComparer<TKey>.Default}}, it doesn't consistently use the passed in
comparer argument everywhere.
I tried that before, but without any way to see how/why it is failing, it is
like shooting in the dark. It would be helpful if you could provide a fix that
works.
One other possibility is to wrap your value type keys inside of reference types
and use those in the declaration of LurchTable. For example:
{code:c#}
// This is pseudo-code - you will probably need to fix it up to compile
private class ValueTypeRef<TKey> //where TKey: struct
{
public TKey Value { get; set }
public override int GetHashCode()
{
return Value?.GetHashCode();
}
public override bool Equals(object other)
{
return Value?.Equals(other);
}
}
cache = new LurchTable<ValueTypeRef<TKey>, TValue>(LurchTableOrder.Access,
limit, comparer);
// and change the rest of the class so it gets/sets the value from/to
ValueTypeRef and only exposes the value type externally...
{code}
> Error using Lucene.Net.Facet 4.8.0-beta00005 with Xamarin.iOS
> --------------------------------------------------------------
>
> Key: LUCENENET-602
> URL: https://issues.apache.org/jira/browse/LUCENENET-602
> Project: Lucene.Net
> Issue Type: Bug
> Components: Lucene.Net.Facet
> Affects Versions: Lucene.Net 4.8.0
> Environment: Xamarin Forms 3.0.0.561731
> Ios 10.3.3 and Higher
> Lucene.Net.Facet 4.8.0-beta00005
> Reporter: Enrico Caltran
> Priority: Blocker
> Labels: AOT, Xamarin.iOS, lucene.net.facet
> Fix For: Lucene.Net 4.8.0
>
> Attachments: AppTestLucene.zip, image-2019-08-08-02-26-40-582.png
>
> Original Estimate: 120h
> Remaining Estimate: 120h
>
> I'm using Lucene.Net.Facet 4.8.0-beta00005 in a big Xamarin project.
> +With Xamarin.Android and Xamarin.UWP it's all right.+
> *+But With Xamarin.iOS on device (Ipad)+*, i'm receiving this error:
> _Attempting to JIT compile method
> 'Lucene.Net.Support.LurchTable2<Lucene.Net.Facet.Taxonomy.FacetLabel,
> Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>:InternalInsert<Lucene.Net.Support.LurchTable2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel,
> Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>>
> (int,Lucene.Net.Facet.Taxonomy.FacetLabel,int&,Lucene.Net.Support.LurchTable`2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel,
> Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>&)'
> while running in aot-only mode. See
> [https://developer.xamarin.com/guides/ios/advanced_topics/limitations/] for
> more information._
> _{color:#d04437}at Lucene.Net.Support.LurchTable2[TKey,TValue].Insert[T]
> (TKey key, T& value) <0x2570f48 + 0x000e0> in
> <063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
> at (wrapper unknown) System.Object.gsharedvt_in() at
> Lucene.Net.Support.LurchTable2[TKey,TValue].AddOrUpdate (TKey key, TValue
> addValue, Lucene.Net.Support.KeyValueUpdate2[TKey,TValue] fnUpdate)
> <0x232824c + 0x0013b> in
> <063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
> at Lucene.Net.Facet.Taxonomy.LRUHashMap2[TKey,TValue].Put (TKey key, TValue
> value) <0x2c487f8 + 0x0015b> in
> <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 at
> Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader.GetOrdinal
> (Lucene.Net.Facet.Taxonomy.FacetLabel cp) <0x2c51970 + 0x0019b> in
> <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 at
> Lucene.Net.Facet.Taxonomy.Int32TaxonomyFacets.GetTopChildren{color}
> (System.Int32 topN, System.String dim, System.String[] path) <0x2c481dc +
> 0x0008f> in
> <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 at
> Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloXRicercaAvanzataConRicercaSemplice
> (System.Collections.Generic.List1[T] listParametri) <0x224add0 +
> 0x001bb> in
> <8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
> at
> Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloConRicercaSemplice
> (System.Collections.Generic.List1[T] listParametri) <0x224afbc + 0x0009f> in
> <8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 at
> MyMB.Forms.RicercaLucene.RicercaArticoloLucene.GetListaArticoliXRicercaSemplice
> (Login.MyMB.Interface.IAmbiente ambiente,
> Login.MyMB.Lucene.Client.LuceneArticoliSearcher las,
> System.Collections.Generic.List`1[T] ListParametri, System.Boolean
> isAbilitataRicercaBarcode) <0xe47fc0 + 0x000e7> in
> <f1bb3149abe145459612794f1a096634#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
> ..............................._
> At the link
> [https://docs.microsoft.com/it-it/xamarin/ios/internals/limitations] , I
> found the problem cause (I suppose...):
> _Value types as Dictionary Keys Using a value type as a Dictionary<TKey,
> TValue> key is problematic, as the default Dictionary constructor attempts to
> use EqualityComparer<TKey>.Default. EqualityComparer<TKey>.Default, in turn,
> attempts to use Reflection to instantiate a new type which implements the
> IEqualityComparer<TKey> interface. This works for reference types (as the
> reflection+create a new type step is skipped), but for value types it crashes
> and burns rather quickly once you attempt to use it on the device.
> Workaround: Manually implement the IEqualityComparer<TKey> interface in a new
> type and provide an instance of that type to the Dictionary<TKey, TValue>
> (IEqualityComparer<TKey>) constructor._
> So, what can I do? Thank you in advance, Enrico Caltran +393357485560
> [[email protected]|mailto:[email protected]]
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)