Skip to content

massive slowdown for nested folding operations #1298

@matthias314

Description

@matthias314

Nested folding operations may lead to massive slowdowns, apparently from 32 bit numbers on:

julia> N = 32; T = Int16; v = [rand(T, N) for _ in 1:1000]; w = map(SVector{N}, v);

julia> @b sum(sum, $v)
11.637 μs

julia> @b sum(sum, $w)
1.401 μs

julia> N = 16; T = Int32; v = [rand(T, N) for _ in 1:1000]; w = map(SVector{N}, v);

julia> @b sum(sum, $v)
10.120 μs

julia> @b sum(sum, $w)
28.138 μs

julia> N = 16; T = Float32; v = [rand(T, N) for _ in 1:1000]; w = map(SVector{N}, v);

julia> @b sum(sum, $v)
10.656 μs

julia> @b sum(sum, $w)
29.554 μs

I've tried out several processors (all x86-64), with the same result. Maybe it's an LLVM issue. Is it known?

Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)

StaticArrays v1.9.13

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