Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/apicompat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
dotnet-version: |
6.x
8.x
10.x
- name: Run API Compatibility Check
run: bash scripts/apicompat.sh --build
2 changes: 1 addition & 1 deletion .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x
- run: dotnet build
- run: dotnet tool update -g docfx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x
- run: dotnet build
- run: dotnet tool update -g docfx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x
- name: Check formatting
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x
- name: Release Build
run: dotnet build -c Release tests/NATS.Client.Perf/NATS.Client.Perf.csproj
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x

- name: Build
run: |
Expand All @@ -71,6 +71,11 @@ jobs:
cd tests/NATS.Client.Abstractions.Tests
dotnet test -c Release --no-build

- name: Test Object Store Encoder
run: |
cd tests/NATS.Client.ObjectStore.Encoder.Tests
dotnet test -c Release --no-build

- name: Test JetStream
run: |
killall nats-server 2> /dev/null | echo -n
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_linux_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x
- name: Build
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
dotnet-version: |
6.x
8.x
9.x
10.x

- name: Set up Go
uses: actions/setup-go@v5
Expand Down Expand Up @@ -83,6 +83,12 @@ jobs:
cd tests/NATS.Client.Abstractions.Tests
dotnet test -c Release --no-build

# net481 covers the netstandard2.0 branch; run TFMs serially as the platform tests do
- name: Test Object Store Encoder
run: |
cd tests/NATS.Client.ObjectStore.Encoder.Tests
dotnet test -c Release --no-build -p:TestTfmsInParallel=false

- name: Test JetStream
run: |
tasklist | grep -i nats-server && taskkill -F -IM nats-server.exe
Expand Down
2 changes: 2 additions & 0 deletions NATS.Net.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Folder Name="/sandbox/">
<Project Path="sandbox/ConsoleApp/ConsoleApp.csproj" />
<Project Path="sandbox/MicroBenchmark/MicroBenchmark.csproj" />
<Project Path="sandbox/MicroBench2/MicroBench2.csproj" />
<Project Path="sandbox/MinimumWebApp/MinimumWebApp.csproj" />
</Folder>
<Folder Name="/Solution Items/">
Expand Down Expand Up @@ -82,6 +83,7 @@
<Project Path="tests/NATS.Client.CoreUnit.Tests/NATS.Client.CoreUnit.Tests.csproj" />
<Project Path="tests/NATS.Client.JetStream.Tests/NATS.Client.JetStream.Tests.csproj" />
<Project Path="tests/NATS.Client.KeyValueStore.Tests/NATS.Client.KeyValueStore.Tests.csproj" />
<Project Path="tests/NATS.Client.ObjectStore.Encoder.Tests/NATS.Client.ObjectStore.Encoder.Tests.csproj" />
<Project Path="tests/NATS.Client.ObjectStore.Tests/NATS.Client.ObjectStore.Tests.csproj" />
<Project Path="tests/NATS.Client.Perf/NATS.Client.Perf.csproj" />
<Project Path="tests/NATS.Client.Platform.Windows.Tests/NATS.Client.Platform.Windows.Tests.csproj" />
Expand Down
1 change: 1 addition & 0 deletions sandbox/MicroBench2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/BenchmarkDotNet.Artifacts
98 changes: 98 additions & 0 deletions sandbox/MicroBench2/Base64UrlEncoderBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using NATS.Client.ObjectStore.Internal;

namespace MicroBench2;

[MemoryDiagnoser]
[ShortRunJob(RuntimeMoniker.Net481)]
[ShortRunJob(RuntimeMoniker.Net80)]
[ShortRunJob(RuntimeMoniker.Net10_0)]
public class Base64UrlEncoderBenchmarks
{
private const char PadChar = '=';

private static readonly char[] SBase64Table =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
};

private byte[] _data = null!;

// SHA-256 digest (32) is the common case; the others bracket small and larger inputs.
[Params(16, 32, 256, 4096)]
public int Size { get; set; }

[GlobalSetup]
public void Setup()
{
_data = new byte[Size];
for (var i = 0; i < Size; i++)
_data[i] = (byte)((i * 37) + 11);
}

// Baseline: the original lookup-table encoder that allocated a fresh char[] per call.
[Benchmark(Baseline = true, Description = "table (new char[])")]
public string EncodeTableNewArray() => EncodeTableNewArrayImpl(_data);

[Benchmark(Description = "current")]
public string Encode() => Base64UrlEncoder.Encode(_data);

private static string EncodeTableNewArrayImpl(Span<byte> inArray)
{
var length = inArray.Length;
if (length == 0)
return string.Empty;

var lengthMod3 = length % 3;
var limit = length - lengthMod3;
var output = new char[(length + 2) / 3 * 4];
var table = SBase64Table;
var j = 0;

for (var i = 0; i < limit; i += 3)
{
var d0 = inArray[i];
var d1 = inArray[i + 1];
var d2 = inArray[i + 2];

output[j + 0] = table[d0 >> 2];
output[j + 1] = table[((d0 & 0x03) << 4) | (d1 >> 4)];
output[j + 2] = table[((d1 & 0x0f) << 2) | (d2 >> 6)];
output[j + 3] = table[d2 & 0x3f];
j += 4;
}

switch (lengthMod3)
{
case 2:
{
var d0 = inArray[limit];
var d1 = inArray[limit + 1];
output[j + 0] = table[d0 >> 2];
output[j + 1] = table[((d0 & 0x03) << 4) | (d1 >> 4)];
output[j + 2] = table[(d1 & 0x0f) << 2];
j += 3;
}

break;

case 1:
{
var d0 = inArray[limit];
output[j + 0] = table[d0 >> 2];
output[j + 1] = table[(d0 & 0x03) << 4];
j += 2;
}

break;
}

for (var k = j; k < output.Length; k++)
output[k] = PadChar;

return new string(output);
}
}
28 changes: 28 additions & 0 deletions sandbox/MicroBench2/MicroBench2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<!--
Lean BenchmarkDotNet host: minimal dependencies (only the projects under test + BDN), kept
separate from MicroBenchmark which pulls in heavier third-party packages. Add focused
micro-benchmarks here. Run with: dotnet run -c Release -f net10.0 (pass a BDN filter such as *).
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<!-- net481 (Windows only) exercises the netstandard2.0 table branch of the encoder. -->
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net481</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.ObjectStore\NATS.Client.ObjectStore.csproj" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions sandbox/MicroBench2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Reflection;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
Loading
Loading