-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Reduce Heap allocations #770
Copy link
Copy link
Open
Labels
Design DiscussionOngoing discussion about design without consensusOngoing discussion about design without consensusEnhancement RequestedProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsPerformancePerformance related issuePerformance related issue
Milestone
Metadata
Metadata
Assignees
Labels
Design DiscussionOngoing discussion about design without consensusOngoing discussion about design without consensusEnhancement RequestedProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsPerformancePerformance related issuePerformance related issue
Type
Fields
Give feedbackNo fields configured for issues without a type.
I have found several instances where we can eliminate heap allocations via simple changes such as iterating over an IList via for loop to avoid the boxing allocation for the enumerator or calling ToString on value types to be passed of to string formatting. On further investigation we are allocating a ton of method group to delegate conversions. From the C# specification section 6.6, describing the run-time evaluation of a method group conversion:
A new instance of the delegate type D is allocated. If there is not enough memory available to allocate the new instance, a System.OutOfMemoryException is thrown and no further steps are executed.
The section for anonymous function conversions (6.5.1) includes this:
Conversions of semantically identical anonymous functions with the same (possibly empty) set of captured outer variable instances to the same delegate types are permitted (but not required) to return the same delegate instance.
And we have lots of places where these conversions happen. If wanted I would love to optimize these problems, the code will stay the same semantically but allocate less.