-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Optimize HttpUtility.UrlEncodeToBytes for (string, Encoding) overload. #102805
Optimize HttpUtility.UrlEncodeToBytes for (string, Encoding) overload. #102805
Conversation
Tagging subscribers to this area: @dotnet/ncl |
Benchmark: [MemoryDiagnoser]
public class HttpUtilityBenchmarks
{
[Benchmark(Baseline = true)]
public byte[] UrlEncodeToBytes() => HttpUtility.UrlEncodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");
[Benchmark]
public byte[] UrlEncodeToBytes_PR() => MyHttpUtility.UrlEncodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");
} Result:
|
Please, ignore me, I am just testing my bot 🙂 @EgorBot -arm64 -amd -profiler using System.Web;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<HttpUtilityBenchmarks>(args: args);
public class HttpUtilityBenchmarks
{
[Benchmark(Baseline = true)]
public byte[] UrlEncodeToBytes() =>
HttpUtility.UrlEncodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");
} |
|
|
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
d550e79
to
da876e9
Compare
Final benchmark results:
|
@EgorBot -arm64 -amd -profiler |
EgorBot manual
All targets are Linux-only at the moment. NOTE: [DisassemblyDiagnoser] may cause unexpected crashes in BDN on Linux (at least on x64) Usage example: link |
@EgorBot -arm64 -amd |
EgorBot manual
All targets are Linux-only at the moment. NOTE: [DisassemblyDiagnoser] may cause unexpected crashes in BDN on Linux (at least on x64) Usage example: link |
@EgorBot -arm64 -amd -profiler using System.Web; BenchmarkRunner.Run(args: args); public class HttpUtilityBenchmarks |
EgorBot manual
All targets are Linux-only at the moment. NOTE: [DisassemblyDiagnoser] may cause unexpected crashes in BDN on Linux (at least on x64) Usage example: link |
@EgorBot -arm64 -amd -profiler using System.Web;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<HttpUtilityBenchmarks>(args: args);
public class HttpUtilityBenchmarks
{
[Benchmark(Baseline = true)]
public byte[] UrlEncodeToBytes() =>
HttpUtility.UrlEncodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");
} |
Benchmark results on Amd
Flame graphs: Main vs PR 🔥 For clean |
Benchmark results on Arm64
Flame graphs: Main vs PR 🔥 For clean |
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Do not allocate byte[] if Encoding.GetMaxByteCount for the string parameter is less than 512 characters.
In this case just encode in stackalloc array.