Skip to content

Performance regression for (*)(A, D::Diagonal) when A is the adjoint of a sparse matrix #1205

@cschwarzbach

Description

@cschwarzbach

Matrix-matrix multiplication with types A <: Adjoint{T, SparseMatrixCSC{T, N}} and B <: Diagonal is significantly slower in Julia 1.11 than in Julia 1.10. The MWE below executes in O(n) time with Julia 1.10, and in O(n2) time with Julia 1.11.

The performance regression appears to have been introduced in PR JuliaLang/julia#52389 that removed specialized methods.

MWE

using LinearAlgebra
using SparseArrays
using BenchmarkTools

n = 100;
A = adjoint(sparse(Float64, I, n, n));
B = Diagonal(ones(n));

print("Julia ", VERSION, ", n = ", n, ":")
@btime *($A, $B)

Output:

Julia 1.10.8, n = 100:  531.160 ns (5 allocations: 2.59 KiB)
Julia 1.11.3, n = 100:  65.927 μs (10 allocations: 8.53 KiB)
Julia 1.10.8, n = 1000:  4.626 μs (5 allocations: 23.88 KiB)
Julia 1.11.3, n = 1000:  6.240 ms (13 allocations: 57.38 KiB)
Julia 1.10.8, n = 10000:  43.303 μs (6 allocations: 234.73 KiB)
Julia 1.11.3, n = 10000:  623.509 ms (13 allocations: 666.56 KiB)
Julia 1.10.8, n = 100000:  450.953 μs (6 allocations: 2.29 MiB)
Julia 1.11.3, n = 100000:  62.992 s (13 allocations: 5.01 MiB)

These results are on a Linux x86-64 platform; similar results were observed on MacOS x86-64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions