Skip to content

MultirangeConverter allocates list without capacity #6513

@dmitry-azaraev

Description

@dmitry-azaraev

Hello!

MultirangeConverter may read multirange into array and into list. See code:

Look at https://github.com/npgsql/npgsql/blob/main/src/Npgsql/Internal/Converters/MultirangeConverter.cs#L36

List<TRange> allocated without capacity:

        var numRanges = reader.ReadInt32();
        var multirange = (T)(object)(typeof(T).IsArray ? new TRange[numRanges] : new List<TRange>());

Unlike array - List somewhy created without capacity, so it grow (realloc) during reading. So it is increases number of allocations and final underlying array is bigger than it needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions