Skip to content

Base.two_mul is constant folding incorrectly on 1.10 (but not 1.9 or 1.11) #52079

Closed
@Moelf

Description

@Moelf

It's useful for something: https://cds.cern.ch/record/2866130/files/ANA-EXOT-2022-18-PAPER.pdf#page=9

(this is a fitting, so you want this exponential to be very fast)

julia> @benchmark x^y setup=begin x=rand(); y=rand()end
BenchmarkTools.Trial: 10000 samples with 988 evaluations.
 Range (min  max):  47.248 ns  440.931 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     47.567 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   49.616 ns ±   4.787 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▅█▇▁     ▂▁       ▁▁▁                ▆▇▄       ▁             ▂
  ████▁▃▄▁▇██▇▇▆▆▆▆▇███▇▇▆▆▆▆▆▅▇▆▆▆▆▆▆█████▇▇▇▇▇███▆▆▆▅▅▆▅▇▇█▇ █
  47.2 ns       Histogram: log(frequency) by time      55.5 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark x^y setup=begin x=rand(); y=rand(3:9)end
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min  max):  2.408 ns  20.031 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     9.003 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   8.631 ns ±  2.849 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▇                           ▇       █     █   ▂
  █▃▂▂▂▂▂▁▂▂▂▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▂█▂▂▁▃▂▇▄█▇▂▂▂▃█▆▂▂█▃▃▇▂▇▆▂▂▂▂▂ ▃
  2.41 ns        Histogram: frequency by time        12.7 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Maybe we're hitting the physical limit of how fast this can go?

In [2]: a=np.random.rand(100);

In [3]: b=np.random.rand(100);

In [5]: %timeit np.power(a,b)
514 ns ± 3.64 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

Metadata

Metadata

Assignees

No one assigned

    Labels

    mathsMathematical functionsperformanceMust go fasterregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions