-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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.JavaScriptStringEncode by using SearchValues #102917
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues #102917
Conversation
@EgorBot -arm64 -amd using System.Web;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<HttpUtilityBenchmarks>(args: args);
public class HttpUtilityBenchmarks
{
[Benchmark(Baseline = true)]
public string JavaScriptStringEncode() =>
HttpUtility.JavaScriptStringEncode("No escaping needed.");
[Benchmark]
public string JavaScriptStringEncode_Encode() =>
HttpUtility.JavaScriptStringEncode("The \t and \n will need to be escaped.");
} |
@TrayanZapryanov please avoid using |
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
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
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
I see we had similar ideas @gfoidl :) |
@gfoidl, @MihaZupan thanks for good ideas.
Allocations are much better, although there is a small regression(most probably due to ValueStringBuilder). In General PR gives good perf wins even now. |
Do you see it go away if you move the fallback (everything after E.g. |
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
@MihaZupan requested changes are applied.
string.IsNullOrEmpty:
I don't think this is so performance critical code, so both ways shows performance increase and it is up to you to decide which one do you prefer. |
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.
Looks like this one hit a merge conflict after #102805
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
9ae9832
to
5d498a4
Compare
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues for invalid JavaScript characters.
Benchmark
Results: