JuliaArrays / JuliaArrays/StaticArrays.jl

3 argument dot is slower than a matmul and two arg dot

Open
#1,287 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

Somewhat counter intuitive:

using LinearAlgebra, StaticArrays, BenchmarkTools

f1(x, A) = dot(x, A * x)
f2(x, A) = dot(x, A, x)
let 
    x = randn(3)
    A = randn(3, 3)
    A = A * A' + 1e-6 * I
    sx = SVector{3}(x...)
    sA = SMatrix{3,3}(A...)
    display(@benchmark(f1($sx, $sA)))
    display(@benchmark(f2($sx, $sA)))
end



BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  2.813 ns … 18.835 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     2.817 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   2.878 ns ±  0.673 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █   ▅▁                                                     ▁
  █▅▁▁██▄▁▄▁▁▁▁▁▇▁▁▁▁▆▃▁▁▃▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▄▄▃▆▇▅ █
  2.81 ns      Histogram: log(frequency) by time     3.54 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  3.815 ns … 54.783 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     3.821 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   3.931 ns ±  1.141 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █  ▆     ▁                                                 ▁
  █▆▅█▅▇▃▅▇█▃▅▃▅▄▅▁▁▁▄▁▁▁▃▁▁▁▁▁▃▃▁▃▁▃▁▁▁▃▁▁▁▁▃▁▃▃▁▁▁▁▄▁▁▁▁▁▃ █
  3.82 ns      Histogram: log(frequency) by time      5.3 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
 Official https://julialang.org/ release
Platform Info:
 OS: Linux (x86_64-linux-gnu)
 CPU: 16 × 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz
 WORD_SIZE: 64
 LLVM: libLLVM-16.0.6 (ORCJIT, rocketlake)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
Environment:
 JULIA_EDITOR = code
 JULIA_NUM_THREADS = 16

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

Start by running the reported Julia 1.11.1 benchmark with dot, f1, f2, SVector, and SMatrix to reproduce the timing difference. The issue names no source file or test; trace the three-argument dot entry point and compare it with the A * x path. Done means the reported performance gap is explained and, if appropriate, covered by a benchmark or regression test.

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.