JuliaArrays / JuliaArrays/StaticArrays.jl

Matrix exponential compiles slowly on Julia 1.0

Open
#631 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

compile-time-performance linear-algebra
Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

Here's a simple example:

julia> using Pkg, LinearAlgebra, StaticArrays;

julia> v = @MMatrix zeros(Float64, 5, 5);

julia> v[2, 3] = -π;

julia> v[3, 2] = π;

julia> v
5×5 MArray{Tuple{5,5},Float64,2,25}:
0.0  0.0       0.0      0.0  0.0
0.0  0.0      -3.14159  0.0  0.0
0.0  3.14159   0.0      0.0  0.0
0.0  0.0       0.0      0.0  0.0
0.0  0.0       0.0      0.0  0.0

On Julia 1.1, this compiles and runs quickly

julia> @time exp(v)
8.741098 seconds (23.58 M allocations: 983.001 MiB, 8.48% gc time)
5×5 MArray{Tuple{5,5},Float64,2,25}:
1.0   0.0           0.0           0.0   0.0
-0.0  -1.0          -2.35127e-16  -0.0  -0.0
0.0   2.35127e-16  -1.0           0.0   0.0
0.0   0.0           0.0           1.0   0.0
0.0   0.0           0.0           0.0   1.0

julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, haswell)

julia> Pkg.status("StaticArrays")
    Status `~/.julia/environments/v1.1/Project.toml`
  [90137ffa] StaticArrays v0.11.0 #master (https://github.com/JuliaArrays/StaticArrays.jl)

On Julia 1.0, it takes nearly 50x longer:

julia> @time exp(v)
406.894653 seconds (24.31 M allocations: 1.512 GiB, 0.31% gc time)
5×5 MArray{Tuple{5,5},Float64,2,25}:
1.0   0.0           0.0           0.0   0.0
-0.0  -1.0          -2.35127e-16  -0.0  -0.0
0.0   2.35127e-16  -1.0           0.0   0.0
0.0   0.0           0.0           1.0   0.0
0.0   0.0           0.0           0.0   1.0

julia> versioninfo()
Julia Version 1.0.4
Commit 38e9fb7f80 (2019-05-16 03:38 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

julia> Pkg.installed()["StaticArrays"]
v"0.11.0"

The culprit appears to be these lines

https://github.com/JuliaArrays/StaticArrays.jl/blob/e77e3ef0bdb12f5dbda0bcfeba21d758616bd2cb/src/expm.jl#L105-L112

If I remove them and everything afterward, the function compiles and returns quickly. Also, if I interrupt the stalled command (exp(v)) with Ctrl+C, and then re-run the command, it runs instantly.

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 with the reproducible StaticArrays example and inspect src/expm.jl at lines 105-112, comparing Julia 1.0.4 with 1.1.0. Measure compilation and execution for exp(v), then identify whether the reported slowdown remains and document or test the resulting behavior.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.