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

SWEEP: Replace J2N's TripleShift call with C# 11's unsigned right shift operator #1007

Merged
merged 3 commits into from
Nov 3, 2024

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Replaces calls to J2N's TripleShift method with the C# 11 unsigned right shift operator (>>>)

Fixes #1006

Description

This more closely matches the Java code, and should improve performance by avoiding method calls and reducing this operation down to one opcode.

@paulirwin
Copy link
Contributor Author

Need to run better benchmarks to be sure, but this seems to result in about a 7% reduction in time to run all the tests on Linux and macOS. Results are negligible on Windows.

@paulirwin paulirwin marked this pull request as ready for review November 2, 2024 23:29
Copy link
Contributor

@NightOwl888 NightOwl888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some places where the extra parentheses were left in, but these don't necessarily need to be fixed. See my comments inline.

I also ran some benchmarks on Windows x64:

IndexFiles

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19045
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=8.0.403
  [Host]              : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  000-4.8.0-beta00014 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  001-4.8.0-beta00015 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  002-4.8.0-beta00016 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  003-4.8.0-beta00017 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  004-With issue/1006 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), 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 000-4.8.0-beta00014 Lucene.Net.Analysis.Common 4.8.0-beta00014 721.0 ms 44.33 ms 63.57 ms 44000.0000 8000.0000 7000.0000 220.21 MB
IndexFiles 001-4.8.0-beta00015 Lucene.Net.Analysis.Common 4.8.0-beta00015 698.5 ms 27.47 ms 38.51 ms 44000.0000 8000.0000 7000.0000 220.46 MB
IndexFiles 002-4.8.0-beta00016 Lucene.Net.Analysis.Common 4.8.0-beta00016 688.2 ms 28.98 ms 40.62 ms 44000.0000 8000.0000 7000.0000 220.45 MB
IndexFiles 003-4.8.0-beta00017 Lucene.Net.Analysis.Common 4.8.0-beta00017 601.5 ms 20.05 ms 29.39 ms 42000.0000 8000.0000 7000.0000 211.61 MB
IndexFiles 004-With issue/1006 Lucene.Net.Analysis.Common 4.8.0-ci0000003030 650.0 ms 39.17 ms 56.17 ms 42000.0000 8000.0000 7000.0000 211.64 MB

Search Files

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19045
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=8.0.403
  [Host]              : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  000-4.8.0-beta00014 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  001-4.8.0-beta00015 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  002-4.8.0-beta00016 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  003-4.8.0-beta00017 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT
  004-With issue/1006 : .NET Core 8.0.10 (CoreCLR 8.0.1024.46610, CoreFX 8.0.1024.46610), X64 RyuJIT

IterationCount=15  LaunchCount=2  WarmupCount=10  
Method Job NuGetReferences Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
SearchFiles 000-4.8.0-beta00014 Lucene.Net.Analysis.Common 4.8.0-beta00014,Lucene.Net.QueryParser 4.8.0-beta00014 118.9 ms 3.16 ms 4.64 ms 14000.0000 1000.0000 - 65.83 MB
SearchFiles 001-4.8.0-beta00015 Lucene.Net.Analysis.Common 4.8.0-beta00015,Lucene.Net.QueryParser 4.8.0-beta00015 139.8 ms 4.63 ms 6.79 ms 14000.0000 1000.0000 - 65.89 MB
SearchFiles 002-4.8.0-beta00016 Lucene.Net.Analysis.Common 4.8.0-beta00016,Lucene.Net.QueryParser 4.8.0-beta00016 151.3 ms 13.73 ms 20.13 ms 14000.0000 1000.0000 - 65.89 MB
SearchFiles 003-4.8.0-beta00017 Lucene.Net.Analysis.Common 4.8.0-beta00017,Lucene.Net.QueryParser 4.8.0-beta00017 168.5 ms 7.64 ms 11.19 ms 14000.0000 1000.0000 - 65.98 MB
SearchFiles 004-With issue/1006 Lucene.Net.Analysis.Common 4.8.0-ci0000003030,Lucene.Net.QueryParser 4.8.0-ci0000003030 158.3 ms 4.85 ms 7.10 ms 14000.0000 1000.0000 - 65.98 MB

If you want to run them on other platforms, here is the branch where I added the benchmarkdotnet changes:

https://github.com/NightOwl888/lucenenet/tree/issue/1006-w-benchmarks

Add the config:

new BuildConfiguration { PackageVersion = "4.8.0-ci0000003030", Id = "With issue/1006" },

And you can download the nuget packages here: https://dev.azure.com/shad0962/Experiments/_build/results?buildId=2496&view=artifacts&pathAsName=false&type=publishedArtifacts

You will probably also have to add an entry to NuGet.config pointing to your local file system for it to pick up the new version.

Tip: Comment everything out except the new version to make sure it compiles before doing the run, otherwise if the NuGet packages are not found it will simply put N/A after waiting for the entire run to finish.

src/Lucene.Net/Util/FixedBitSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net/Util/FixedBitSet.cs Outdated Show resolved Hide resolved
src/Lucene.Net/Util/OpenBitSet.cs Outdated Show resolved Hide resolved
@paulirwin paulirwin added this to the 4.8.0-beta00018 milestone Nov 3, 2024
@paulirwin paulirwin merged commit 4b491f1 into apache:master Nov 3, 2024
199 checks passed
@paulirwin paulirwin deleted the issue/1006 branch November 3, 2024 22:33
@NightOwl888 NightOwl888 added the notes:performance-improvement Contains a performance improvement label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:performance-improvement Contains a performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace J2N.Numerics.BitOperation.TripleShift with >>> in C# 11
2 participants