Skip to content

Reduce Heap allocations #770

@Mrnikbobjeff

Description

@Mrnikbobjeff

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design DiscussionOngoing discussion about design without consensusEnhancement RequestedProduct code improvement that does NOT require public API changes/additionsPerformancePerformance related issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions