Skip to content

Performance improvement for .NET 9.0+ #558

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

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET SDK 8.0.x
- name: Setup .NET SDK 9.0.x
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Show dotnet Version
run: |
10 changes: 8 additions & 2 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
@@ -38,10 +38,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET SDK 8.0.x
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: |
8.0.x
9.0.x

- name: Show dotnet Version
run: |
@@ -59,3 +61,7 @@ jobs:
- name: Run tests on net8.0
run: |
dotnet test --framework=net8.0 /home/runner/work/EasyCaching/EasyCaching/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj

- name: Run tests on net9.0
run: |
dotnet test --framework=net9.0 /home/runner/work/EasyCaching/EasyCaching/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Build with dotnet
run: dotnet build --configuration Release /home/runner/work/EasyCaching/EasyCaching/EasyCaching.sln
- name: Pack with dotnet
2 changes: 1 addition & 1 deletion .github/workflows/release_stable.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Build with dotnet
run: dotnet build --configuration Release /home/runner/work/EasyCaching/EasyCaching/EasyCaching.sln
- name: Pack with dotnet
34 changes: 17 additions & 17 deletions bus/EasyCaching.Bus.Zookeeper/DefaultZookeeperBus.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace EasyCaching.Bus.Zookeeper
using EasyCaching.Core;
using EasyCaching.Core.Bus;
using EasyCaching.Core.Serialization;
using Microsoft.Extensions.Options;
using org.apache.zookeeper;
using org.apache.zookeeper.data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace EasyCaching.Bus.Zookeeper
{
using EasyCaching.Core;
using EasyCaching.Core.Bus;
using EasyCaching.Core.Serialization;
using Microsoft.Extensions.Options;
using org.apache.zookeeper;
using org.apache.zookeeper.data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

public class DefaultZookeeperBus : EasyCachingAbstractBus
{
/// <summary>
@@ -41,7 +41,7 @@ public class DefaultZookeeperBus : EasyCachingAbstractBus
/// <summary>
/// lock
/// </summary>
private readonly object _zkEventLock = new object();
private readonly Lock _zkEventLock = LockFactory.Create();

/// <summary>
/// The serializer.
@@ -214,7 +214,7 @@ private async Task SubscribeDataChange(WatchedEvent @event)
/// <returns></returns>
private async Task ReZkConnect()
{
if (!Monitor.TryEnter(_zkEventLock, _zkBusOptions.ConnectionTimeout))
if (!_zkEventLock.TryEnter(_zkBusOptions.ConnectionTimeout))
return;
try
{
@@ -234,7 +234,7 @@ private async Task ReZkConnect()
}
finally
{
Monitor.Exit(_zkEventLock);
_zkEventLock.Exit();
}
}

10 changes: 9 additions & 1 deletion bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
<Import Project="../../build/version.props" />
<Import Project="../../build/releasenotes.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Owners>ncc;Catcher Wong</Owners>
<Authors>ncc;Catcher Wong</Authors>
<VersionPrefix>$(EasyCachingZookeeperBusPackageVersion)</VersionPrefix>
@@ -40,4 +41,11 @@
<PackageReference Include="ZooKeeperNetEx" Version="3.4.12.4" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="2.0.7" />
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>


2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/DistributedLock.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ namespace EasyCaching.Core.DistributedLock
public class DistributedLock : MemoryLock
{
private readonly IDistributedLockProvider _provider;
private readonly object _syncObj = new object();
private readonly Lock _syncObj = LockFactory.Create();
private readonly DistributedLockOptions _options;
private readonly ILogger _logger;

2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/MemoryLock.cs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public class MemoryLock : IDistributedLock

public string Key { get; }

private readonly object _syncObj = new object();
private readonly Lock _syncObj = LockFactory.Create();

public MemoryLock(string key) => Key = key;

16 changes: 15 additions & 1 deletion src/EasyCaching.Core/EasyCaching.Core.csproj
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
<Import Project="../../build/version.props" />
<Import Project="../../build/releasenotes.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Owners>ncc;Catcher Wong</Owners>
<Authors>ncc;Catcher Wong</Authors>
<VersionPrefix>$(EasyCachingCorePackageVersion)</VersionPrefix>
@@ -44,8 +45,21 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="2.0.7" />
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ protected override IEasyCachingProvider CreateCachingProvider(Action<BaseProvide
}

/*[Fact]
public async void Use_Redis6_ACL_Should_Succeed()
public async Task Use_Redis6_ACL_Should_Succeed()
{
IServiceCollection services = new ServiceCollection();
services.AddEasyCaching(x =>
Original file line number Diff line number Diff line change
@@ -417,7 +417,7 @@ public void Provider_Information_Should_Be_Correct()
public class MemcachedProviderNoConnectionTest
{
[Fact]
public async void NoConnectionTest()
public async Task NoConnectionTest()
{
IServiceCollection services = new ServiceCollection();
services.AddLogging();
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@
var first = res.Value.First();

Assert.Equal("ss", first.Key);
Assert.Equal(1, first.Value.Count);

Check warning on line 91 in test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs

GitHub Actions / build on windows-latest

Do not use Assert.Equal() to check for collection size. Use Assert.Single instead. (https://xunit.net/xunit.analyzers/rules/xUnit2013)

Check warning on line 91 in test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs

GitHub Actions / build on windows-latest

Do not use Assert.Equal() to check for collection size. Use Assert.Single instead. (https://xunit.net/xunit.analyzers/rules/xUnit2013)

Check warning on line 91 in test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs

GitHub Actions / build and test on ubuntu-latest

Do not use Assert.Equal() to check for collection size. Use Assert.Single instead. (https://xunit.net/xunit.analyzers/rules/xUnit2013)

Check warning on line 91 in test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs

GitHub Actions / build and test on ubuntu-latest

Do not use Assert.Equal() to check for collection size. Use Assert.Single instead. (https://xunit.net/xunit.analyzers/rules/xUnit2013)

Check warning on line 91 in test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs

GitHub Actions / build and test on ubuntu-latest

Do not use Assert.Equal() to check for collection size. Use Assert.Single instead. (https://xunit.net/xunit.analyzers/rules/xUnit2013)
}

[Fact]
@@ -156,7 +156,7 @@
}

[Fact]
public async void Issues497_GetCountAsync_Check_Expires_Test()
public async Task Issues497_GetCountAsync_Check_Expires_Test()
{
for (int i = 0; i < 9; i++)
{