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 difference between local Ref (allocated once) and a local float #20452

Closed
amitmurthy opened this issue Feb 4, 2017 · 1 comment
Closed
Labels
performance Must go faster

Comments

@amitmurthy
Copy link
Contributor

Timing differences between summing into a local Ref (allocated once) vs a local float.

No difference when adding 1.0 a billion times
Ref takes 50% more time when adding rand() a billion times

julia> function foo1(n)
           a = Ref(0.0)
           for i in 1:10^n
               a.x += 1.0
           end
           a.x
       end
foo1 (generic function with 1 method)

julia> function bar1(n)
           a = 0.0
           for i in 1:10^n
               a += 1.0
           end
           a
       end
bar1 (generic function with 1 method)

julia> function foorand(n)
           a = Ref(0.0)
           for i in 1:10^n
               a.x += rand()
           end
           a.x
       end
foorand (generic function with 1 method)

julia> function barrand(n)
           a = 0.0
           for i in 1:10^n
               a += rand()
           end
           a
       end
barrand (generic function with 1 method)

julia> foo1(1); bar1(1); foorand(1); barrand(1);

julia> @time foo1(9)
  0.942448 seconds (6 allocations: 192 bytes)
1.0e9

julia> @time bar1(9)
  0.960316 seconds (5 allocations: 176 bytes)
1.0e9

julia> @time foorand(9)
  3.020439 seconds (6 allocations: 192 bytes)
4.9999308850923723e8

julia> @time barrand(9)
  1.964119 seconds (5 allocations: 176 bytes)
4.999952968904752e8
@yuyichao
Copy link
Contributor

yuyichao commented Feb 4, 2017

I believe this is #16969 and #15369. We are just hitting the cache harder and running more instructions for an otherwise very cheap loop. Note that foo1 and bar1 has the same performance because LLVM can prove that it is legal to delay the store to the ref until the end of the loop since there's no synchronization point in the loop.

yuyichao added a commit that referenced this issue Jul 5, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 5, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 5, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit to yuyichao/julia that referenced this issue Jul 5, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix JuliaLang#20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 8, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 9, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 9, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit to yuyichao/julia that referenced this issue Jul 9, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix JuliaLang#20452
yuyichao added a commit that referenced this issue Jul 9, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 9, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 10, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 15, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit to yuyichao/julia that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix JuliaLang#20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 17, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 22, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 22, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 24, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
yuyichao added a commit that referenced this issue Jul 27, 2017
This can obtain escape information with much higher precision than what we can currently do
in typeinf. However, it does not replace the alloc_elim_pass! in type inference either since
this cannot handle objects with reference fields.

Fix #20452
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

2 participants