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

Performance improvement for .NET 9.0+ #558

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v3
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Show dotnet Version
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,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@v3
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Show dotnet Version
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
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
Expand Down
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>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
{
Expand All @@ -234,7 +234,7 @@ private async Task ReZkConnect()
}
finally
{
Monitor.Exit(_zkEventLock);
_zkEventLock.Exit();
}
}

Expand Down
10 changes: 9 additions & 1 deletion bus/EasyCaching.Bus.Zookeeper/EasyCaching.Bus.Zookeeper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Up @@ -2,7 +2,7 @@

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

Expand Down
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>
Expand Down
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>
Expand Down
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>
Expand Down
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>


Expand Down
2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/DistributedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/EasyCaching.Core/DistributedLock/MemoryLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 15 additions & 1 deletion src/EasyCaching.Core/EasyCaching.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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

View workflow job for this annotation

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)
}

[Fact]
Expand Down Expand Up @@ -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++)
{
Expand Down
Loading