Uh oh!
There was an error while loading. Please reload this page.
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues - #102917
Conversation
TrayanZapryanov
commented
May 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
commented
May 31, 2024
@TrayanZapryanov please avoid using |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MihaZupan
commented
May 31, 2024
I see we had similar ideas @gfoidl :) |
TrayanZapryanov
commented
May 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. |
Do you see it go away if you move the fallback (everything after E.g. |
Uh oh!
There was an error while loading. Please reload this page.
TrayanZapryanov
commented
Jun 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. |
Uh oh!
There was an error while loading. Please reload this page.
9ae9832 to
5d498a4Compare
Optimize HttpUtility.JavaScriptStringEncode by using SearchValues for invalid JavaScript characters.
Benchmark
Results: