Skip to content

Migrate to .NET 10 from .NET 8 - #1333

Merged
NicolasDorier merged 8 commits into
MetacoSA:masterfrom
Carti-it:net10
Sep 8, 2026
Merged

NicolasDorier merged 8 commits into
MetacoSA:masterfrom
Carti-it:net10

Conversation

@Carti-it

@Carti-it Carti-it commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

One thing that I cannot really explain is this:

master (net8.0)

cd NBitcoin.Bench
dotnet run -f net8.0 -c Release -- --runtimes net8.0 --filter *HexBench*
Method hexString Mean Error StdDev Gen0 Allocated
DecodeData ? 25.11 ns 0.434 ns 0.385 ns 0.0089 56 B
DecodeDataLongSpan ? 4,030.49 ns 79.167 ns 102.940 ns 1.6289 10264 B
EncodeData ? 64.81 ns 1.324 ns 2.583 ns 0.0485 304 B
DecodeDataSpan 00000(...)fffff [64] 32.56 ns 0.679 ns 1.171 ns 0.0089 56 B
DecodeDataSpan 0000(...)ffff [128] 47.32 ns 0.967 ns 1.588 ns 0.0140 88 B
DecodeDataSpan 0000(...)ffff [192] 64.95 ns 1.325 ns 3.780 ns 0.0191 120 B

PR (net10.0)

cd NBitcoin.Bench
dotnet run -f net10.0 -c Release -- --runtimes net10.0 --filter *HexBench*
Method hexString Mean Error StdDev Gen0 Allocated
DecodeData ? 40.50 ns 0.704 ns 0.659 ns 0.0089 56 B
DecodeDataLongSpan ? 9,580.75 ns 166.571 ns 155.811 ns - -
EncodeData ? 17.18 ns 0.276 ns 0.258 ns 0.0242 152 B
DecodeDataSpan 00000(...)fffff [64] 35.94 ns 0.402 ns 0.356 ns - -
DecodeDataSpan 0000(...)ffff [128] 64.46 ns 1.107 ns 0.981 ns - -
DecodeDataSpan 0000(...)ffff [192] 99.97 ns 1.786 ns 1.671 ns - -

(This was measured with the latest BenchmarkDotNet version (v0.15.8) and I did the same for .NET 8. So that's not the reason.)

Decoding HEX on .NET 10 seems to be slower than on .NET 8. I think that all other perf improvements of .NET 10 outweighs this one but still I don't really know what the issue might be. I kept playing with it for a while but I don't know.

Perhaps

  • it's a really a genuine regression in .NET 10,
  • or it needs to be reproduced on a different machine than mine
  • or perhaps something like dotnet run -f net8.0 -c Release -- --runtimes net10.0,net8.0 --filter *HexBench* would be more fair comparison.

I don't know.

using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
data = new byte[fs.Length - 32];
fs.Read(data, 0, data.Length);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This reports an analyzer warning because it can return after a partial read.

Comment thread NBitcoin/NBitcoin.csproj
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net472;netstandard2.1;netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net472;netstandard2.1;netstandard2.0</TargetFrameworks>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

net10.0 TFM was moved everywhere to be the first entry in <TargetFrameworsk> to unify it in code.

Comment thread NBitcoin/PriorityQueue.cs
@@ -1,4 +1,4 @@
#if !NET6_0_OR_GREATER && !NO_TUPLE
#if !NET10_0_OR_GREATER && !NO_TUPLE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Easier to find in the future

Comment thread .github/workflows/CI.yml
@@ -6,47 +6,47 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done based on fa4e677

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net10.0</TargetFrameworks>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done based on dc5118a

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Required for .NET 10 support

/// </summary>
public ExtPubKey(ReadOnlySpan<byte> bytes)
{
if (bytes == null)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning: span cannot be null

#endif

#if NET10_0_OR_GREATER
public override string EncodeData(ReadOnlySpan<byte> data)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to avoid byte[] allocations.

<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit" Version="2.9.3" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

xunit package is deprecated.

WalletWasabi/WalletWasabi#14864 - upgrade to xUnit v3 is not that hard

@NicolasDorier

Copy link
Copy Markdown
Collaborator

@Carti-it I find it weird that 8.0 was faster.
Did you try just bumping 10.0 without the call to Convert.ToHexStringLower? Might it be the code path isn't used?

@Carti-it

Carti-it commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@Carti-it I find it weird that 8.0 was faster.

Yes. It's unexpected. I would expect better times, or at worst the same times. Certainly not worse.

Did you try just bumping 10.0 without the call to Convert.ToHexStringLower?

Yes. It was also slower. About the same as now.

Might it be the code path isn't used?

I run tests with the debugger on and the .NET 10 code paths get hit. So I don't think this is the issue.

@Carti-it

Carti-it commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@NicolasDorier Perhaps you can try to measure it on your machine.

@Carti-it

Carti-it commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

dotnet/runtime#133350

@NicolasDorier

Copy link
Copy Markdown
Collaborator

that was fast, even pinpointed on dotnet/runtime wow

@NicolasDorier
NicolasDorier merged commit c7dcbd3 into MetacoSA:master Sep 8, 2026
6 checks passed
@Carti-it
Carti-it deleted the net10 branch September 8, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants