- Notifications
You must be signed in to change notification settings - Fork5.2k
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues#102917
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues#102917
Uh oh!
There was an error while loading.Please reload this page.
Conversation
TrayanZapryanov commentedMay 31, 2024
@EgorBot -arm64 -amd usingSystem.Web;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkRunner.Run<HttpUtilityBenchmarks>(args:args);publicclassHttpUtilityBenchmarks{[Benchmark(Baseline=true)]publicstringJavaScriptStringEncode()=>HttpUtility.JavaScriptStringEncode("No escaping needed.");[Benchmark]publicstringJavaScriptStringEncode_Encode()=>HttpUtility.JavaScriptStringEncode("The\t and\n will need to be escaped.");} |
EgorBo commentedMay 31, 2024
@TrayanZapryanov please avoid using |
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
MihaZupan commentedMay 31, 2024
I see we had similar ideas@gfoidl :) |
TrayanZapryanov commentedMay 31, 2024
@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. |
MihaZupan commentedMay 31, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
TrayanZapryanov commentedJun 3, 2024
@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. |
MihaZupan left a comment
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
9ae9832 to5d498a4Compare
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues for invalid JavaScript characters.
Benchmark
Results: