Skip to content
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

Fix perf regression in System.Net.NetworkInformation.PhysicalAddress #40571

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libraries/Common/src/System/HexConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static void ToCharsBuffer(byte value, Span<char> buffer, int startingInde
buffer[startingIndex] = (char)(packedResult >> 8);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not getting inlined already? I wonder why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods with loops are generally too large to inline by default.

To confirm, you can try:

  • BDN's inlining diagnoser
  • enable and look at the jit inlining events under perfview
  • Use a checked jit and set COMPlus_JitPrintInlinedMethods=<class_name>.<method name>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not getting inlined already? I wonder why

It is considered unprofitable... (as per BDN inlining diagnoser)

--------------------
Inliner: System.HexConverter+<>c.<ToString>b__4_0 - instance void  (value class System.Span`1<wchar>,value class System.ValueTuple`3<int,int32,value class Casing>)
Inlinee: System.HexConverter.EncodeToUtf16 - void  (value class System.ReadOnlySpan`1<unsigned int8>,value class System.Span`1<wchar>,value class Casing)
Fail Reason: unprofitable inline
--------------------

public static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars, Casing casing = Casing.Upper)
{
Debug.Assert(chars.Length >= bytes.Length * 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override bool Equals(object? comparand)

public override string ToString()
{
return Convert.ToHexString(_address.AsSpan());
return HexConverter.ToString(_address.AsSpan(), HexConverter.Casing.Upper);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's concerning if the brand new public API is insufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not concerted as we are talking about nanoseconds here.
A public API with input validation will never be a match for an internal method that gets straight to business. Especially with such short input values (16 bytes).

There is also #39702 to improve things (perf). The initial PR adding the public API was kept simple by design (to get it in for .NET 5).

}

public byte[] GetAddressBytes()
Expand Down