Skip to content

stack not specialized for SparseVectors as it is forhcat #50623

Closed
@VPetukhov

Description

@VPetukhov

This is a follow up on #49887 . Replacing calls to hcat with stack leads to 500+ fold drop in performance:

Code:

using SparseArrays
using BenchmarkTools

vs = [sprand(Bool, 100, 0.1) for i in 1:20000];

Benchmarks:

@benchmark stack(vs, dims=2)
 Range (min … max):  698.288 ms … 750.043 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     703.131 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   708.654 ms ±  17.297 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%
 Memory estimate: 3.79 MiB, allocs estimate: 27.
@benchmark hcat(vs...)
BenchmarkTools.Trial: 2524 samples with 1 evaluation.
 Range (min … max):  1.112 ms … 31.250 ms  ┊ GC (min … max): 0.00% … 88.59%
 Time  (median):     1.814 ms              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.968 ms ±  1.940 ms  ┊ GC (mean ± σ):  6.47% ±  6.20%
 Memory estimate: 2.64 MiB, allocs estimate: 20008.

The test was done on julia 1.8.5, as hcat(vs...) fails on 1.9.*. However, testing stack on 1.9.2 produces almost the same results.

versioninfo()

For 1.8.5:

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 64 × Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, broadwell)
  Threads: 1 on 64 virtual cores

For 1.9.2:

Julia Version 1.9.2
Commit e4ee485e909 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 64 × Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, broadwell)
  Threads: 1 on 64 virtual cores

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