Skip to content

memory allocation increases unexpectedly in sparse getindex at a threshold #18051

@ViralBShah

Description

@ViralBShah

@pranavbhat and I were looking into sparse vector indexing performance issues, and discovered this. Basically, as the size of the input becomes larger than 512, more allocations happen, increasing by exactly 4 bytes with every increment in the input size:

foo(x) = for i=1:length(x); getindex(x, i); end

julia> @time foo(sparse(ones(100)));
  0.000044 seconds (16 allocations: 7.469 KB)

julia> @time foo(sparse(ones(512)));
  0.000066 seconds (16 allocations: 19.938 KB)

julia> @time foo(sparse(ones(513)));
  0.000068 seconds (20 allocations: 36.156 KB)

julia> @time foo(sparse(ones(520)));
  0.000070 seconds (32 allocations: 20.500 KB)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions