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

Minor record ToString improvements #54630

Merged
merged 7 commits into from
Jul 13, 2021

Conversation

Rekkonnect
Copy link
Contributor

@Rekkonnect Rekkonnect commented Jul 6, 2021

Closes #54600

This implements all the mentioned improvements

  • reduced calls to Append(string)
  • preferring usage of Append(char)

Additionally, also changes some tests to comfort to the new changes to the emitted IL and diagnostics.

Effects

As measured from the diffs of the expected emitted IL tests:

  • ToString gets a -6 byte code size
  • PrintMembers gets -12 byte code size for 1 member, -36 for 2, expected formula: -12 - 24 * (members - 1)

AlFas added 2 commits July 6, 2021 15:03
I don't know exactly what else must be done to ensure that Append(char) will be successfully referred to
All the headers for each new printable member are merged into one compiled string
@Rekkonnect Rekkonnect requested a review from a team as a code owner July 6, 2021 12:06
@Rekkonnect Rekkonnect marked this pull request as draft July 6, 2021 13:45
@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 6, 2021
@Rekkonnect Rekkonnect marked this pull request as ready for review July 7, 2021 23:28
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

Personally, I'm just fine with a minor improvement to code gen size if someone wants to contribute it and it looks good.

@jcouv, could you take a look?

@jcouv jcouv self-assigned this Jul 12, 2021
block.Add(makeAppendString(F, builder, " = "));
var memberHeader = $"{member.Name} = ";
if (i > 0)
memberHeader = ", " + memberHeader;
Copy link
Member

Choose a reason for hiding this comment

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

nit: please use braces to match rest of the code

@@ -87,6 +87,10 @@ static BoundStatement makeAppendString(SyntheticBoundNodeFactory F, BoundLocal b
{
return F.ExpressionStatement(F.Call(receiver: builder, F.WellKnownMethod(WellKnownMember.System_Text_StringBuilder__AppendString), F.StringLiteral(value)));
}
static BoundStatement makeAppendChar(SyntheticBoundNodeFactory F, BoundLocal builder, char value)
Copy link
Member

Choose a reason for hiding this comment

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

nit: empty line to separate methods would be desirable

@@ -4903,25 +4911,21 @@ public void ToString_TopLevelRecord_OneField_ValueType()

v.VerifyIL("C1." + WellKnownMemberNames.PrintMembersMethodName, @"
{
// Code size 50 (0x32)
// Code size 38 (0x26)
Copy link
Member

Choose a reason for hiding this comment

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

I'd say the reduction in IL size is probably the biggest benefit. I think that's nice. Thanks

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 6) with some formatting nits. Please let us know if could address, then we'll merge.

@Rekkonnect Rekkonnect requested a review from jcouv July 13, 2021 11:39
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

@jcouv for another look.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 7)

@jcouv jcouv enabled auto-merge (squash) July 13, 2021 16:47
@jcouv jcouv merged commit dec4f47 into dotnet:main Jul 13, 2021
@ghost ghost added this to the Next milestone Jul 13, 2021
@Rekkonnect Rekkonnect deleted the record-tostring-improvements branch July 13, 2021 17:30
@jcouv
Copy link
Member

jcouv commented Jul 13, 2021

Merged/squashed. Thanks @alfasgd for the contribution!

@allisonchou allisonchou modified the milestones: Next, 17.0.P3 Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Records' ToString can get minor performance improvements
4 participants