- Notifications
You must be signed in to change notification settings - Fork5.2k
Optimize allocations in HttpUtility.UrlDecodeToBytes for smaller inputs.#102753
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 allocations in HttpUtility.UrlDecodeToBytes for smaller inputs.#102753
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Tagging subscribers to this area: @dotnet/ncl |
TrayanZapryanov commentedMay 28, 2024
Benchmark: [MemoryDiagnoser]publicclassHttpUtilityBenchmarks{[Benchmark(Baseline=true)]publicbyte[]UrlDecodeToBytes()=>HttpUtility.UrlDecodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");[Benchmark]publicbyte[]UrlDecodeToBytes_PR()=>MyHttpUtility.UrlDecodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");} Results:
|
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.
Thank you for looking into making improvements here.
Is the existing test coverage here sufficient to catch any potential regressions?
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/HttpUtility.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/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
EgorBo commentedMay 28, 2024
@EgorBot -intel -arm64 -profiler usingBenchmarkDotNet.Attributes;usingSystem.Web;usingBenchmarkDotNet.Running;BenchmarkRunner.Run<HttpUtilityBenchmarks>(args:args);publicclassHttpUtilityBenchmarks{[Benchmark]publicbyte[]UrlDecodeToBytes()=>HttpUtility.UrlDecodeToBytes("http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r");} |
Uh oh!
There was an error while loading.Please reload this page.
EgorBot commentedMay 28, 2024
|
EgorBot commentedMay 28, 2024
|
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.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.
| [return:NotNullIfNotNull(nameof(bytes))] | ||
| publicstaticbyte[]?UrlDecodeToBytes(byte[]?bytes)=>bytes==null?null:UrlDecodeToBytes(bytes,0,bytes.Length); | ||
| publicstaticbyte[]?UrlDecodeToBytes(byte[]?bytes)=>bytes==null?null:HttpEncoder.UrlDecode(bytes.AsSpan(0,bytes.Length)); |
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.
| publicstaticbyte[]?UrlDecodeToBytes(byte[]?bytes)=>bytes==null?null:HttpEncoder.UrlDecode(bytes.AsSpan(0,bytes.Length)); | |
| publicstaticbyte[]?UrlDecodeToBytes(byte[]?bytes)=>bytes==null?null:HttpEncoder.UrlDecode(bytes.AsSpan()); |
For future reference (not worth restarting CI on this PR)
Optimize byte[] allocation when:
If a "happy" path is taken, we will have allocations equals to the returned byte[].
Drawback: method will be a bit slower as we need to calculate Encoding.GetMaxByteCount(xxx)