Skip to content

Performance regression in version 1.8 for exp of complex argument #46323

Closed
@simonp0420

Description

@simonp0420

I noticed a slowdown when switching from 1.7.3 to 1.8-rc4 in a function that performs millions of complex exponentials. Benchmarking shows a small but significant slowdown in 1.8. The first two benchmarks below are for 1.7.3 and show that the complex exponential is just as fast as using exp on the real part of the argument and cis on the imaginary part. But for 1.8, the last two benchmarks show that exp is slower by about 2 nsec.

~ >>> julia -t8                                                                
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.3 (2022-05-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8

julia> using BenchmarkTools

julia> z = complex(-0.8, 22.34*pi)
-0.8 + 70.18317988119598im

julia> @benchmark exp($z)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  13.525 ns … 36.088 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     14.751 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   14.825 ns ±  1.036 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                                 █                             
  ▂▁▁▂▂▂▁▂▂▂▂▁▂▂▂▂▂▂▂▄█▂▂▂▁▃▃▂▂▂▇█▃▁▂▂▇▄▁▂▂▃▃▁▂▂▂▃▂▂▁▂▃▃▁▂▂▂▂ ▂
  13.5 ns         Histogram: frequency by time        15.8 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark exp(real($z)) * cis(imag($z))
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  14.411 ns … 60.727 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     14.696 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   14.851 ns ±  1.520 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

          ▂█▃                                                  
  ▂▁▂▂▂▂▂▃███▇▅▄▅▇▅▃▃▃▂▂▂▂▂▂▁▂▁▁▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▁▁▁▁▂▁▂▂▁▂▂ ▃
  14.4 ns         Histogram: frequency by time          16 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.


julia> 
~ >>> julia +rc -t8                                                            
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.0-rc4 (2022-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> versioninfo()
Julia Version 1.8.0-rc4
Commit 7853436ccd7 (2022-08-08 07:55 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 8

julia> using BenchmarkTools

julia> z = complex(-0.8, 22.34*pi)
-0.8 + 70.18317988119598im

julia> @benchmark exp($z)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  16.669 ns … 57.521 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     16.786 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   16.841 ns ±  1.144 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                      ▂▃▃▄▃▄▂▆▆▇██▄▇▆▆▅▄▂ ▂▁                   
  ▁▁▁▁▁▁▁▁▂▃▃▄▄▄▆▆▆█████████████████████████▇▅▅▃▃▂▂▂▂▂▂▂▂▂▁▁▁ ▄
  16.7 ns         Histogram: frequency by time        16.9 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark exp(real($z)) * cis(imag($z))
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  14.835 ns … 52.246 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     14.891 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   14.994 ns ±  1.412 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

      ▁▆▅▆▆▇▇█▃                                                
  ▂▂▃▆██████████▆▄▄▃▂▂▂▂▁▂▂▂▂▂▁▁▁▂▂▂▁▁▂▂▂▂▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▂▂ ▃
  14.8 ns         Histogram: frequency by time        15.2 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions