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

mod. and floor. in combination are much slower than if seperated #22999

Closed
zsoerenm opened this issue Jul 28, 2017 · 5 comments
Closed

mod. and floor. in combination are much slower than if seperated #22999

zsoerenm opened this issue Jul 28, 2017 · 5 comments
Assignees
Labels
performance Must go faster

Comments

@zsoerenm
Copy link
Contributor

zsoerenm commented Jul 28, 2017

mod. and floor. in combination are much slower than if both are seperated:

@benchmark mod.(floor.(Int,1:0.1:20000),1000)

BenchmarkTools.Trial: 
  memory estimate:  12.09 MiB
  allocs estimate:  692465
  --------------
  minimum time:     16.307 ms (0.00% GC)
  median time:      17.317 ms (4.88% GC)
  mean time:        17.368 ms (3.04% GC)
  maximum time:     23.773 ms (0.00% GC)
  --------------
  samples:          288
  evals/sample:     1

@benchmark begin
       c = floor.(Int,1:0.1:20000)
       mod.(c,1000)
end

BenchmarkTools.Trial: 
  memory estimate:  3.05 MiB
  allocs estimate:  4
  --------------
  minimum time:     1.412 ms (0.00% GC)
  median time:      1.479 ms (0.00% GC)
  mean time:        1.615 ms (6.02% GC)
  maximum time:     3.623 ms (22.50% GC)
  --------------
  samples:          3092
  evals/sample:     1
versioninfo()
Julia Version 0.6.0
Commit 903644385b* (2017-06-19 13:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libblas
  LAPACK: liblapack
  LIBM: libm
  LLVM: libLLVM-4.0.0 (ORCJIT, skylake)

BTW here are the results if I do it the other way round:

@benchmark floor.(Int, mod.(1:0.1:20000,1000))

BenchmarkTools.Trial: 
  memory estimate:  1.53 MiB
  allocs estimate:  2
  --------------
  minimum time:     3.304 ms (0.00% GC)
  median time:      3.397 ms (0.00% GC)
  mean time:        3.462 ms (0.86% GC)
  maximum time:     5.196 ms (0.00% GC)
  --------------
  samples:          1444
  evals/sample:     1

@test floor.(Int, mod.(1:0.1:20000,1000)) == mod.(floor.(Int,1:0.1:20000),1000)
Test Passed

@KristofferC
Copy link
Member

Something with the closure not specializing on the type Int perhaps?

@yuyichao
Copy link
Contributor

Seems to be an allocation elimination issue. More aggressive slots and ssavalue elimination already seem to fix it.

@KristofferC
Copy link
Member

KristofferC commented Jul 29, 2017

More aggressive slots and ssavalue elimination already seem to fix it.

Could you elaborate on that? Is there a PR / branch that does this or did you tweak some tolerance value for how much to try eliminate?

@yuyichao
Copy link
Contributor

Is there a PR / branch that does this or did you tweak some tolerance value for how much to try eliminate?

Local branch.

@KristofferC
Copy link
Member

Seems fixed:

julia> @btime mod.(floor.(Int,1:0.1:20000),1000);
  1.400 ms (2 allocations: 1.53 MiB)

julia> @btime begin
              c = floor.(Int,1:0.1:20000)
              mod.(c,1000)
       end
  1.249 ms (4 allocations: 3.05 MiB)

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

No branches or pull requests

4 participants