Skip to content

Conversation

@davkean
Copy link
Member

@davkean davkean commented Jul 11, 2017

This allocation was causing 1.4% of all allocations in the trace in dotnet/project-system#2576.

image

This allocation was causing 1.4% of all allocations in the trace in dotnet/project-system#2576.
@davkean davkean requested review from a team and CyrusNajmabadi July 11, 2017 02:50
@sharwell
Copy link
Contributor

sharwell commented Jul 11, 2017

@davkean Can you check the other locations from #20171 and see if they are also affected?

@davkean
Copy link
Member Author

davkean commented Jul 11, 2017

I checked all callers of StartNew, and verified that they were already using this overload, was there anything else?

// to do this work. That way we don't end up blocking the threadpool.
var task = Task.Factory.StartNew(
() => WriteArrayValues(array),
a => WriteArrayValues((Array)a),
Copy link
Member

Choose a reason for hiding this comment

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

wait... doesn't this still need to capture 'this'?

Copy link
Member Author

@davkean davkean Jul 11, 2017

Choose a reason for hiding this comment

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

@CyrusNajmabadi and I spoke offline. There's still an allocation of a delegate - it doesn't appear to be showing at all on the radar. I looked at the code gen and figured out why:

  • The first thing that the compiler does in the method is instantiate the capture class and "capture" array.
  • It then replaces all reads/writes of the parameter to the field in the capture class

Basically, in summary it looks like this method is always paying for the capture class regardless of the branch. That's why the delegate creation itself isn't showing - the branch is never hit.

@davkean
Copy link
Member Author

davkean commented Jul 11, 2017

I filed #20775 #20777 to track the unexpected code gen here - but I suspect based on the fact that the compiler reuses the capture class's field as if it was the parameter that this was deliberate.

@davkean davkean merged commit 70d5193 into dotnet:master Jul 11, 2017
@davkean davkean deleted the RemoveAllocation branch July 13, 2017 23:59
@davkean davkean restored the RemoveAllocation branch August 9, 2017 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants