-
Notifications
You must be signed in to change notification settings - Fork 642
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
FieldDoc.Fields boxing issue #429
Comments
Possible SolutionI took a look at this and how changing FieldDoc // Make FieldDoc<T>
FieldDoc.Fields // Change from object[] to T[]
IndexSearcher.SearchAfter(ScoreDoc after, Query query, int n, Sort sort) // Change ScoreDoc to FieldDoc<T>
IndexSearcher.SearchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort) // Change ScoreDoc to FieldDoc<T>
IndexSearcher.SearchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore) // Change ScoreDoc to FieldDoc<T>
IndexSearcher.Search(Weight weight, FieldDoc after, int nDocs, Sort sort, bool fillFields, bool doDocScores, bool doMaxScore) // Change FieldDoc to FieldDoc<T>
TopFieldCollector.Create(Sort sort, int numHits, FieldDoc after, bool fillFields, bool trackDocScores, bool trackMaxScore, bool docsScoredInOrder) // Change FieldDoc to FieldDoc<T>
TopFieldCollector.PagingFieldCollector // Change to PagingFieldCollerctor<T> (this class is private)
TopFieldCollector.PagingFieldCollector(FieldValueHitQueue<Entry> queue, FieldDoc after, int numHits, bool fillFields, bool trackDocScores, bool trackMaxScore) // ctor: Change FieldDoc to FieldDoc<T>
FieldComparer.SetTopValue(object value) // Change to SetTopValue<TValue>(TValue value)
FieldComparer<T>.SetTopValue(object value) // Change to SetTopValue(T value) and overload SetTopValue<T>(T value).
ToParentBlockJoinFieldComparer : FieldComparer<object> // Rely on SetTopValue<T>(T value) rather than SetTopValue(object value)? The class cannot be made generic easily due to its usage in ToParentBlockJoinSortField.GetComparer(int numHits, int sortPos).
The public abstract SetTopValue(T value);
public override SetTopValue<TValue>(TValue value) // Added for .NET to eliminate boxing
{
SetTopValue((T)(object)value);
} This is a little weird because the base type uses a generic method and the subclass is a generic closing type, but given the leaky nature of generics and the fact that some types don't have a reasonable way to pass the generic without also becoming generic this seems like a reasonable compromise. I am open to suggestions if someone can come up with something that seems more natural than this.
|
A potential problem with the above approach is that it is difficult to cast |
So, @rclabo and I have been analyzing this in more detail and it is clear that As an alternative, some design proposals to BenchmarksCast to NumberClick to expand!BenchmarkDotNet=v0.12.0, OS=Windows 10.0.19041
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.104
[Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Job-TNEQUD : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
InvocationCount=1 UnrollFactor=1
CopyClick to expand!BenchmarkDotNet=v0.12.0, OS=Windows 10.0.19041
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.104
[Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Job-CBNWUR : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
InvocationCount=1 UnrollFactor=1
Fill FieldsClick to expand!BenchmarkDotNet=v0.12.0, OS=Windows 10.0.19041
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.104
[Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Job-TNEQUD : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
InvocationCount=1 UnrollFactor=1
Set Top ValueClick to expand!BenchmarkDotNet=v0.12.0, OS=Windows 10.0.19041
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.104
[Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Job-ZELLKO : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
InvocationCount=1 UnrollFactor=1
Clearly, allocations used in the The leading contender, BoxingWrappedReferenceScenario takes us a step back toward the Lucene design and although the details are not worked out, here are some of the basics:
Of course, none of this is set in stone, but it is clear that fixing this problem will likely involve breaking some public APIs at least a little so I am moving this to the |
…to use reference types for numerics (from J2N) to avoid boxing (fixes apache#429)
…to use reference types for numerics (from J2N) to avoid boxing (fixes apache#429)
…to use reference types for numerics (from J2N) to avoid boxing (fixes apache#429)
…to use reference types for numerics (from J2N) to avoid boxing (fixes apache#429)
…to use reference types for numerics (from J2N) to avoid boxing (fixes #429)
The
Lucene.Net.Search.FieldDoc.Fields
property returnsobject[]
. However, according to the documentation, it is designed to be used withstring
,int
, orfloat
.In Java, this was not an issue because there are numeric reference types that primitive numbers are wrapped in when passed around. But, since it would not be a good user experience to require wrapper classes for numeric types in .NET we should solve the boxing issue another way.
The text was updated successfully, but these errors were encountered: