-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Use stackalloc char&byte arrays for decoding Url values in HttpUtiliy.ParseQueryString #102745
Conversation
TrayanZapryanov
commented
May 28, 2024
- Convert UrlDecoder to ref struct
- If Url is less than 256 characters, do no allocate char&byte arrays
- Replace substring operation with Span
…y.ParseQueryString
|
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
Outdated
Show resolved
Hide resolved
|
Benchmark: [MemoryDiagnoser]
public class HttpUtilityBenchmarks
{
private static string UnicodeStr
=> new string(new[] { '\u304a', '\u75b2', '\u308c', '\u69d8', '\u3067', '\u3059' });
private static string EncodedUnicodeStr => HttpUtility.UrlEncode(UnicodeStr) + "=" + HttpUtility.UrlEncode(UnicodeStr);
[Benchmark(Baseline = true)]
public NameValueCollection ParseQueryString() => HttpUtility.ParseQueryString("https://portal.azure.com/#@testgroup.onmicrosoft.com/dashboard/arm/subscriptions/111111-abac-4067-81ba-5ae054d891b5/" +
"resourcegroups/dashboards/providers/microsoft.portal/dashboards/3456268-8630-60f7-aaac-eca38aca231");
[Benchmark]
public NameValueCollection ParseQueryString_Mix() => HttpUtility.ParseQueryString("ReturnUrl=http%3a%2f%2flocalhost%2flogin%2fauthenticate%3fReturnUrl%3dhttp%3a%2f%2flocalhost%2fsecured_area%26__provider__%3dgoogle");
[Benchmark]
public NameValueCollection ParseQueryString_Unicode() => HttpUtility.ParseQueryString(EncodedUnicodeStr);
}Results: Before:
PR:
|
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.
This is one weird class.
Thanks for taking care of these low-hanging fruit
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
….ParseQueryString (dotnet#102745)

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
