lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] NightOwl888 opened a new pull request #384: Fix for IndexOptions.CompareTo() Boxing (Closes #375, Closes #376)
Date Tue, 03 Nov 2020 22:55:57 GMT

NightOwl888 opened a new pull request #384:
URL: https://github.com/apache/lucenenet/pull/384


   This addresses #375 and #376 by adding a custom comparer to take the place of the `IndexOptions.CompareTo()`
method. Many thanks to @theolivenbaum for identifying this issue.
   
   Unfortunately, Microsoft doesn't provide a built-in way to compare enum values without
boxing or casting to the enum base type. To avoid the maintenance headache of doing casting
everywhere `IndexOptions` is compared, this adds a new class `IndexOptionsComparer` that can
be used in a similar way to the `IndexOptions.CompareTo()` method.
   
   ```c#
   // Instead of:
   public override bool HasFreqs => fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS)
>= 0;
   
   // Use:
   // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare()
   public override bool HasFreqs => IndexOptionsComparer.Default.Compare(fieldInfo.IndexOptions,
IndexOptions.DOCS_AND_FREQS) >= 0;
   ```
   
   Since `IndexOptions` comparison is a critical part of building a custom codec, the `IndexOptionsComparer`
class was marked public.
   
   ## Benchmarks
   
   ### IndexFiles
   
   ``` ini
   
   BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.1082 (1909/November2018Update/19H2)
   Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
   .NET Core SDK=3.1.403
     [Host]                    : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00005           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00006           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00007           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00008           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00009           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00010           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00011           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00012           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-wip00_before_GH-375 : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-wip01_after_GH-375  : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
   
   InvocationCount=1  IterationCount=15  LaunchCount=2  
   UnrollFactor=1  WarmupCount=10  
   
   ```
   |     Method |                       Job |                               NuGetReferences
|     Mean |    Error |   StdDev |      Gen 0 |     Gen 1 |     Gen 2 | Allocated |
   |----------- |-------------------------- |----------------------------------------------
|---------:|---------:|---------:|-----------:|----------:|----------:|----------:|
   | IndexFiles |           4.8.0-beta00005 |    Lucene.Net.Analysis.Common 4.8.0-beta00005
| 679.3 ms | 13.60 ms | 19.06 ms | 43000.0000 | 8000.0000 | 7000.0000 | 220.95 MB |
   | IndexFiles |           4.8.0-beta00006 |    Lucene.Net.Analysis.Common 4.8.0-beta00006
| 665.8 ms | 14.26 ms | 19.99 ms | 43000.0000 | 8000.0000 | 7000.0000 | 220.96 MB |
   | IndexFiles |           4.8.0-beta00007 |    Lucene.Net.Analysis.Common 4.8.0-beta00007
| 672.1 ms | 17.31 ms | 25.91 ms | 44000.0000 | 8000.0000 | 7000.0000 | 220.89 MB |
   | IndexFiles |           4.8.0-beta00008 |    Lucene.Net.Analysis.Common 4.8.0-beta00008
| 675.5 ms | 17.20 ms | 25.21 ms | 44000.0000 | 8000.0000 | 7000.0000 | 221.28 MB |
   | IndexFiles |           4.8.0-beta00009 |    Lucene.Net.Analysis.Common 4.8.0-beta00009
| 676.5 ms | 14.56 ms | 20.88 ms | 44000.0000 | 8000.0000 | 7000.0000 |  221.2 MB |
   | IndexFiles |           4.8.0-beta00010 |    Lucene.Net.Analysis.Common 4.8.0-beta00010
| 665.1 ms | 10.58 ms | 15.18 ms | 44000.0000 | 8000.0000 | 7000.0000 | 221.26 MB |
   | IndexFiles |           4.8.0-beta00011 |    Lucene.Net.Analysis.Common 4.8.0-beta00011
| 673.2 ms | 15.83 ms | 22.19 ms | 44000.0000 | 8000.0000 | 7000.0000 | 221.15 MB |
   | IndexFiles |           4.8.0-beta00012 |    Lucene.Net.Analysis.Common 4.8.0-beta00012
| 715.0 ms | 13.32 ms | 19.52 ms | 56000.0000 | 7000.0000 | 6000.0000 | 286.96 MB |
   | IndexFiles | 4.8.0-wip00_before_GH-375 | Lucene.Net.Analysis.Common 4.8.0-ci0000002207
| 698.9 ms | 20.86 ms | 31.22 ms | 43000.0000 | 8000.0000 | 7000.0000 | 220.02 MB |
   | IndexFiles |  4.8.0-wip01_after_GH-375 | Lucene.Net.Analysis.Common 4.8.0-ci0000002208
| 679.2 ms | 11.51 ms | 16.13 ms | 44000.0000 | 8000.0000 | 7000.0000 | 220.09 MB |
   
   
   ### SearchFiles
   
   ``` ini
   
   BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.1082 (1909/November2018Update/19H2)
   Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
   .NET Core SDK=3.1.403
     [Host]                    : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00005           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00006           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00007           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00008           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00009           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00010           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00011           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-beta00012           : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-wip00_before_GH-375 : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
     4.8.0-wip01_after_GH-375  : .NET Core 3.1.9 (CoreCLR 4.700.20.47201, CoreFX 4.700.20.47203),
X64 RyuJIT
   
   IterationCount=15  LaunchCount=2  WarmupCount=10  
   
   ```
   |      Method |                       Job |                                           
                             NuGetReferences |      Mean |    Error |    StdDev |     Gen
0 |    Gen 1 |    Gen 2 | Allocated |
   |------------ |-------------------------- |----------------------------------------------------------------------------------------
|----------:|---------:|----------:|----------:|---------:|---------:|----------:|
   | SearchFiles |           4.8.0-beta00005 |       Lucene.Net.Analysis.Common 4.8.0-beta00005,Lucene.Net.QueryParser
4.8.0-beta00005 | 150.61 ms | 3.420 ms |  5.119 ms | 8750.0000 | 500.0000 |        - |  41.39
MB |
   | SearchFiles |           4.8.0-beta00006 |       Lucene.Net.Analysis.Common 4.8.0-beta00006,Lucene.Net.QueryParser
4.8.0-beta00006 | 149.03 ms | 5.427 ms |  8.122 ms | 8750.0000 | 500.0000 |        - |  41.37
MB |
   | SearchFiles |           4.8.0-beta00007 |       Lucene.Net.Analysis.Common 4.8.0-beta00007,Lucene.Net.QueryParser
4.8.0-beta00007 | 153.45 ms | 9.524 ms | 13.659 ms | 8750.0000 | 500.0000 | 250.0000 |  41.28
MB |
   | SearchFiles |           4.8.0-beta00008 |       Lucene.Net.Analysis.Common 4.8.0-beta00008,Lucene.Net.QueryParser
4.8.0-beta00008 |  88.01 ms | 1.232 ms |  1.806 ms | 8666.6667 | 500.0000 |        - |  40.33
MB |
   | SearchFiles |           4.8.0-beta00009 |       Lucene.Net.Analysis.Common 4.8.0-beta00009,Lucene.Net.QueryParser
4.8.0-beta00009 |  87.22 ms | 1.490 ms |  2.137 ms | 8666.6667 | 500.0000 |        - |  40.33
MB |
   | SearchFiles |           4.8.0-beta00010 |       Lucene.Net.Analysis.Common 4.8.0-beta00010,Lucene.Net.QueryParser
4.8.0-beta00010 |  95.42 ms | 6.018 ms |  8.820 ms | 8600.0000 |        - |        - |   40.2
MB |
   | SearchFiles |           4.8.0-beta00011 |       Lucene.Net.Analysis.Common 4.8.0-beta00011,Lucene.Net.QueryParser
4.8.0-beta00011 |  90.31 ms | 3.172 ms |  4.748 ms | 8666.6667 | 500.0000 |        - |  40.19
MB |
   | SearchFiles |           4.8.0-beta00012 |       Lucene.Net.Analysis.Common 4.8.0-beta00012,Lucene.Net.QueryParser
4.8.0-beta00012 |  88.97 ms | 2.541 ms |  3.725 ms | 8833.3333 | 333.3333 |        - |  40.81
MB |
   | SearchFiles | 4.8.0-wip00_before_GH-375 | Lucene.Net.Analysis.Common 4.8.0-ci0000002207,Lucene.Net.QueryParser
4.8.0-ci0000002207 |  89.47 ms | 1.449 ms |  2.031 ms | 8666.6667 | 333.3333 |        - |
 40.17 MB |
   | SearchFiles |  4.8.0-wip01_after_GH-375 | Lucene.Net.Analysis.Common 4.8.0-ci0000002208,Lucene.Net.QueryParser
4.8.0-ci0000002208 |  85.10 ms | 2.326 ms |  3.409 ms | 7000.0000 | 333.3333 |        - |
 33.17 MB |
   
   This patch improves search time slightly and reduces search RAM consumption by more than
17%.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message