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
Add new overloads with ReadOnlySpan to System.Net.NetworkInformation.PhysicalAddress #26214
Comments
Would it make sense to move |
IMO we should not merge |
We have
Adding API is not free. It has cost also on platform usability (choice from more overloads adds tax on developers). Personally, I am skeptical that the Span overloads would help to make any real-world DHCP parser app measurably faster. It feels more like premature optimization to me, but maybe I am wrong about it or there are other scenarios where it matters. On related note: If there was no |
Then |
@karelz Thanks for sharing .Net Core team policy!
I agree that the choice of a large number of APIs adds complexity for developers. But really this complication appears if similar things are done in different places (namespaces). |
Triage: Networking team is fine to take these APIs for larger review. |
We should also have namespace System.Net.NetworkInformation
{
public class PhysicalAddress
{
public static bool TryParse(string address, out PhysicalAddress value);
public static bool TryParse(ReadOnlySpan<char> address, out PhysicalAddress value);
public static PhysicalAddress Parse(ReadOnlySpan<char> address);
// Existing
// public static PhysicalAddress Parse(string address);
}
} |
@terrajobst What is the use-case for a |
This PR introduces two new PhysicalAddress.TryParse methods taking span and string as well as adds a PhysicalAddress.Parse overload taking span. Fixes dotnet/corefx#29780
Rationale
Coming from #26188.
Let's to consider a scenario of DHCP log parsing. We read line by line and parse the line to get fields. Previously we used Substring() method. My understanding is that now best practice (from Stephen Toub) is to use Slice() to exclude extra allocations. So suggested overloads with ReadOnlySpan can be useful.
It is very perf-sensitive - sizes of DHCP logs can reach huge sizes in enterprises. We could use perl or php (or sed/awk) but why we should refuse favourite C# and PowerShell?
About "The API is rare". (1) Although it is rare but we all already have this Parse (string address); - why if it is rare? (2) Why such APIs should remain not optimized? Adding and having ReadOnlySpan overloads is too expensive? I'd like to see a policy and guidance from your team.
Proposed API
The text was updated successfully, but these errors were encountered: