-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Remove capture allocation from WriteArray #20775
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
Conversation
This allocation was causing 1.4% of all allocations in the trace in dotnet/project-system#2576.
|
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), |
There was a problem hiding this comment.
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'?
There was a problem hiding this comment.
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.
This allocation was causing 1.4% of all allocations in the trace in dotnet/project-system#2576.