Skip to content

Reduce generic exception code bloat in System.Linq #18906

@jamesqo

Description

@jamesqo

Currently System.Linq uses this pattern to handle invalid arguments:

if (source == null)
{
    throw Error.ArgumentNull(nameof(source));
}

Where ArgumentNull gets inlined. This introduces significant jitted code bloat since the Linq methods are generic, so this code (which very rarely gets hit) is generated over and over again for different value types.

We should convert all of this to the form

if (source == null)
{
    Error.ThrowSourceArgumentNull(); // or ThrowArgumentNullSource
}

As of dotnet/coreclr#6103 methods that are known to throw are not inlined, so this should help decrease code size.

cc @benaadams

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.LinqenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions