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

Performance regression in Julia v0.5 #385

Closed
MikaelSlevinsky opened this issue Oct 4, 2016 · 7 comments
Closed

Performance regression in Julia v0.5 #385

MikaelSlevinsky opened this issue Oct 4, 2016 · 7 comments

Comments

@MikaelSlevinsky
Copy link
Member

This isn't officially an ApproxFun issue, but the following is a performance anomaly in v0.5. Without loading ApproxFun, the simple function f evaluates fast and allocation-free:

julia> versioninfo()
Julia Version 0.5.1-pre+2
Commit f0d40ec* (2016-09-20 03:34 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin16.0.0)
  CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

julia> f(x::Complex{Float64}) = exp(im*(1.0/x+x-x^3/12.0))::Complex{Float64}
f (generic function with 1 method)

julia> z = 1.0+im
1.0 + 1.0im

julia> @time f(z)
  0.042085 seconds (37.53 k allocations: 1.641 MB, 34.28% gc time)
-0.06858891931151362 + 0.7132409685234511im

julia> @time f(z)
  0.000004 seconds (5 allocations: 192 bytes)
-0.06858891931151362 + 0.7132409685234511im

We try the same thing with the development branch of ApproxFun loaded first, and f is significantly slower and allocates:

julia> using ApproxFun

julia> f(x::Complex{Float64}) = exp(im*(1.0/x+x-x^3/12.0))::Complex{Float64}
f (generic function with 1 method)

julia> z = 1.0+im
1.0 + 1.0im

julia> @time f(z)
  0.037003 seconds (59.92 k allocations: 2.544 MB)
-0.06858891931151362 + 0.7132409685234511im

julia> @time f(z)
  0.000064 seconds (12 allocations: 320 bytes)
-0.06858891931151362 + 0.7132409685234511im

The type-assertion is irrelevant (unless one cares to look at the result of @code_warntype). It would be great for this to be demystified. CC: @yuyichao @tkelman, Julia experts.

The problem is magnified when one vectorizes f.

@yuyichao
Copy link
Contributor

yuyichao commented Oct 4, 2016

Ref JuliaLang/julia#18465

@MikaelSlevinsky
Copy link
Member Author

Does this mean ApproxFun breaks type-stability of Complex{Float64}?

@yuyichao
Copy link
Contributor

yuyichao commented Oct 4, 2016

I don't know what exactly happens for either case but they look similar.

@dlfivefifty
Copy link
Member

@yuyichao So is the solution to stick to 0.4 until JuliaLang/julia#18465 is resolved?

@yuyichao
Copy link
Contributor

I've heard that it is what a few people does. I didn't hit it myself and I didn't look into it (@vtjnash should have) so I don't really have more to say other than pointing to the issue.....

@MikaelSlevinsky
Copy link
Member Author

This appears not to be an issue in 0.6. Without ApproxFun:

julia> versioninfo()
Julia Version 0.6.0-pre.alpha.173
Commit 93cddfc* (2017-03-18 17:19 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin16.4.0)
  CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

julia> f(x::Complex{Float64}) = exp(im*(1.0/x+x-x^3/12.0))::Complex{Float64}
f (generic function with 1 method)

julia> z = 1.0+im
1.0 + 1.0im

julia> @time f(z)
  0.070867 seconds (86.66 k allocations: 3.526 MiB)
-0.06858891931151362 + 0.7132409685234511im

julia> @time f(z)
  0.000005 seconds (5 allocations: 192 bytes)
-0.06858891931151362 + 0.7132409685234511im

With ApproxFun, the run-time and allocations are back to normal, but the compile time is higher.

julia> using ApproxFun

julia> f(x::Complex{Float64}) = exp(im*(1.0/x+x-x^3/12.0))::Complex{Float64}
f (generic function with 1 method)

julia> z = 1.0+im
1.0 + 1.0im

julia> @time f(z)
  0.167900 seconds (183.24 k allocations: 7.191 MiB)
-0.06858891931151362 + 0.7132409685234511im

julia> @time f(z)
  0.000004 seconds (5 allocations: 192 bytes)
-0.06858891931151362 + 0.7132409685234511im

@dlfivefifty
Copy link
Member

dlfivefifty commented Mar 19, 2017 via email

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

No branches or pull requests

3 participants