-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constant
stackalloc
can be optimized by the JIT. (#569)
* Constant `stackalloc` can be optimized by the JIT. dotnet/runtime#54186 (comment) * Fix ESXXX KID computation cause by incorrect canonicalized JWK size ('crv' was computed as base64-encoded) * `EllipticalCurve` is now a class instead of a readonly struct. This reduce the cost of struct copy.
- Loading branch information
1 parent
6db64a2
commit 8f7d759
Showing
51 changed files
with
678 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Security.Cryptography; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Diagnosers; | ||
|
||
namespace JsonWebToken.Performance | ||
{ | ||
[MemoryDiagnoser] | ||
[DisassemblyDiagnoser] | ||
public class StructCopyBenchmark | ||
{ | ||
[Params(true, false)] | ||
public bool includePrivateParameters; | ||
|
||
private ECParameters _parameters = new ECParameters { Curve = ECCurve.NamedCurves.nistP256, D = new byte[32], Q = new ECPoint { X = new byte[32], Y = new byte[32] } }; | ||
|
||
[Benchmark(Baseline = true)] | ||
public ECParameters ExportParameters_Old() | ||
{ | ||
var parameters = new ECParameters | ||
{ | ||
Q = _parameters.Q, | ||
Curve = _parameters.Curve | ||
}; | ||
if (includePrivateParameters) | ||
{ | ||
parameters.D = _parameters.D; | ||
} | ||
|
||
return parameters; | ||
} | ||
|
||
[Benchmark] | ||
public ECParameters ExportParameters_Old2() | ||
{ | ||
var parameters = new ECParameters | ||
{ | ||
Q = _parameters.Q, | ||
Curve = _parameters.Curve | ||
}; | ||
parameters.D = includePrivateParameters ? _parameters.D : null; | ||
|
||
return parameters; | ||
} | ||
[Benchmark] | ||
public ECParameters ExportParameters_Brute() | ||
{ | ||
return _parameters; | ||
} | ||
[Benchmark] | ||
public ECParameters ExportParameters_Brute2() | ||
{ | ||
var p = _parameters; | ||
return p; | ||
} | ||
|
||
[Benchmark] | ||
public ECParameters ExportParameters_New() | ||
{ | ||
var parameters = _parameters; | ||
|
||
if (!includePrivateParameters) | ||
{ | ||
parameters.D = null; | ||
} | ||
|
||
return parameters; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.