Skip to content

Performance regression from findall depwarn suggestion #26183

@sbromberger

Description

@sbromberger

Prompted by this deprecation warning:

 Warning: In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.

I decided to do a (n admittedly worst-case) test: A = rand(10_000, 10_000);

julia> @time u = findall(x->x != 0, A);            # this assumes 0 = zero(eltype(A))
  8.606016 seconds (65.73 k allocations: 260.716 MiB, 2.96% gc time)

julia> @time v = findall(!iszero, A);
 12.464981 seconds (40 allocations: 1.531 GiB, 4.27% gc time)

julia> @time w = findall((!iszero).(A));
  1.531174 seconds (23 allocations: 1.502 GiB, 12.50% gc time)

julia> u == v == w
true

Had I taken the recommended approach, I would've run into a pretty bad performance regression. As it stands, the best (time) performing approach is among the worst in memory usage; the recommended approach with the anonymous function is bad in time but best in memory, and the negative function is worst in both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions