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

Optimize default(T) deconstruction #21232

Closed
alrz opened this issue Aug 1, 2017 · 3 comments
Closed

Optimize default(T) deconstruction #21232

alrz opened this issue Aug 1, 2017 · 3 comments
Assignees
Labels
Area-Compilers Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Tenet-Performance Regression in measured performance of the product from goals.
Milestone

Comments

@alrz
Copy link
Contributor

alrz commented Aug 1, 2017

Version Used: master

Steps to Reproduce:

void M(out int i, out string j) {
  (i, j) = default((int, string));
}

Expected Behavior: (decompiled)

void M(out int i, out string j) {
  i = 0;    // default(int)
  j = null; // default(string)
}

Actual Behavior:

void M(out int i, out string j) {
  i = default((int, string)).Item1;
  j = default((int, string)).Item2;
}

PS: Ideally, this should work for default literal as well (dotnet/csharplang#583).

@jaredpar jaredpar added Area-Compilers Tenet-Performance Regression in measured performance of the product from goals. Feature Request labels Aug 1, 2017
@jaredpar jaredpar added this to the 16.0 milestone Aug 1, 2017
@HaloFour
Copy link

HaloFour commented Aug 2, 2017

Interesting case. I bet the confusion is the compiler dealing with a default of the tuple literal. If you used (default(string), default(int)) instead the compiler does optimize out the tuple. What's particularly strange is that the compiler is emitting and initializing two tuples instead of one.

At least the JIT is correctly optimizing away the use of the tuples, but I agree that the compiler could be handling this better.

@alrz
Copy link
Contributor Author

alrz commented Aug 2, 2017

What's particularly strange is that the compiler is emitting and initializing two tuples instead of one.

I think that's because default(..) is known to be side-effect free between reads so it's not stored in a local.

PS: Looking at IL, actually there is a local to store the result, but I suppose that's how initobj works.

@jcouv jcouv modified the milestones: 16.0, 15.7, 15.8 Mar 26, 2018
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Mar 30, 2018
@jcouv jcouv modified the milestones: 15.8, 16.0 Mar 30, 2018
@jcouv jcouv added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. labels Apr 3, 2018
@jcouv
Copy link
Member

jcouv commented Apr 3, 2018

Fixed in the feature branch for "deconstruction on default". Actual release not yet finalized.

@jcouv jcouv closed this as completed Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature Request Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Tenet-Performance Regression in measured performance of the product from goals.
Projects
None yet
Development

No branches or pull requests

4 participants