JuliaArrays / JuliaArrays/StaticArrays.jl

massive slowdown for nested folding operations

Open
#1,298 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Julia REPL benchmarks from the issue with StaticArrays v1.9.13, comparing nested sum on ordinary vectors and SVector values across the listed element types and sizes. Investigate the generated performance or compiler behavior to determine why some nested folds slow down, then document a confirmed cause and regression coverage or a focused fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.