Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceedingly long compilation time of a function involving StaticArrays #24286

Closed
giordano opened this issue Oct 23, 2017 · 8 comments
Closed

Comments

@giordano
Copy link
Contributor

giordano commented Oct 23, 2017

I have a function which takes way too much to be compiled on Julia master, 10x slower than on Julia 0.6. It involves StaticArrays.jl. Actually, this package seems to be quite broken right now on Julia master, just entering the line Svector makes Julia crash very badly.

That said, until a couple of days ago this function:

using StaticArrays

const A1 = SVector(collect(1.0:60.0))
const B1 = SVector(collect(1.0:60.0))
const C1 = SVector(collect(1.0:60.0))
const D1 = SVector(collect(1.0:60.0))
const A2 = SVector(collect(1.0:60.0))
const B2 = SVector(collect(1.0:60.0))
const C2 = SVector(collect(1.0:60.0))
const D2 = SVector(collect(1.0:60.0))

function test()
    arg1 = A1 * 1.0 + B1 * 2.0 + C1 * 3.0 + D1 * 4.0
    arg2 = A2 * 1.0 + B2 * 2.0 + C2 * 3.0 + D2 * 4.0
    e = sin.(arg1)
    f = cos.(arg1)
    g = sin.(arg2)
end

took about 9-10 seconds to be run the fist time on Julia master (so including compilation time), while it takes ~0.9 seconds to be run the first time on Julia 0.6. The code returned by @code_llvm on Julia master is loooong, more than 5k lines, it doesn't fit in my terminal screen. My full (non-minimal) function takes actually even longer to be compiled, about 35 seconds, In Julia 0.6 it takes 1.5 seconds, what seems to cause the huge slowdown should be those sin and cos calls.

I was trying to reduce further the example, but a few minutes ago I updated Julia and I don't have the time to go back to a working version.

@pkofod
Copy link
Contributor

pkofod commented Oct 24, 2017

This is probably due to the inlining that is due to be removed again in

#24117

:)

@giordano
Copy link
Contributor Author

Thanks for looking into this! I'll let you know if this is indeed fixed by merging your PR as soon as I'll be able to use StaticArrays.jl again on master.

@fredrikekre
Copy link
Member

Seems to be back on 0.6 times after #24117. Timings for first and second call:

julia> @time test();
  0.973949 seconds (776.59 k allocations: 36.718 MiB, 1.00% gc time)

julia> @time test();
  0.000012 seconds (5 allocations: 704 bytes)

@giordano
Copy link
Contributor Author

giordano commented Oct 26, 2017

How can you run the code at all?

julia> using StaticArrays

julia> const A1 = SVector(collect(1.0:60.0))
ERROR: UndefVarError: S not defined
Stacktrace:
 [1] StaticArrays.Size(::Type{SYSTEM: show(lasterr) caused an error
UndefVarError(:N)

Stacktrace:
 [1] StaticArrays.Size(::Type{StaticArrays.SArray{Tuple{S},T,1,S} where T where S}) at /home/mose/.julia/v0.7/StaticArrays/src/traits.jl:51
 [2] length(::Type{StaticArrays.SArray{Tuple{S},T,1,S} where T where S}) at /home/mose/.julia/v0.7/StaticArrays/src/abstractarray.jl:2
 [3] convert at /home/mose/.julia/v0.7/StaticArrays/src/convert.jl:21 [inlined]
 [4] StaticArrays.SArray{Tuple{S},T,1,S} where T where S(::Array{Float64,1}) at /home/mose/.julia/v0.7/StaticArrays/src/convert.jl:4
 [5] eval(::Module, ::Expr) at ./repl/REPL.jl:3
 [6] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./repl/REPL.jl:69
 [7] macro expansion at ./repl/REPL.jl:100 [inlined]
 [8] (::getfield(Base.REPL, Symbol("##1#2")){Base.REPL.REPLBackend})() at ./event.jl:96

@fredrikekre
Copy link
Member

¯\_(ツ)_/¯ Used current julia master (7ae9955) and StaticArrays master (JuliaArrays/StaticArrays.jl@715fefe)

@giordano
Copy link
Contributor Author

Exactly same configuration here...

@fredrikekre
Copy link
Member

Oh, and I also changed SVector(collect(1.0:60.0)) to SVector(1.0:60.0...), seems like the constructor from Vector is broken.

@giordano
Copy link
Contributor Author

You cheated! ;-) Ok, now it works for me and the reported issue is indeed fixed, thanks. However, running the function is slightly slower on master than on Julia 0.6, 2.400 μs vs 2.127 μs, according to BenchmarkTools.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants