-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Order-dependent/redefinition-dependent allocations with functions using keyword arguments #28940
Comments
Calling
Curiously, |
Would be interesting to profile this and show the trace (with |
This is (perhaps unsurprisingly) unaffected by #29086, but here are some profiling results run on that PR's branch in any case: | | |_| | | | (_| | | Version 1.1.0-DEV.207 (2018-09-07)
_/ |\__'_|_|_|\__'_| | jb/kwfunc_nothrow_fix/3459b880d9 (fork: 1 commits, 0 days)
|__/ |
julia> using Profile, BenchmarkTools
julia> @noinline f(; a=1) = a
f (generic function with 1 method)
julia> @noinline g(; a=1//2) = f(a=a)
g (generic function with 1 method)
julia> h() = for i in 1:1e7; g(); end
h (generic function with 1 method)
julia> h(); Profile.clear(); @time @profile h(); Profile.print(C=true)
0.358387 seconds (40.00 M allocations: 1.192 GiB, 8.64% gc time)
358 /home/schmrlng/code/oss/julia-master/src/task.c:271; start_task
358 /home/schmrlng/code/oss/julia-master/src/julia.h:1558; jl_apply
358 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
358 ./task.jl:259; (::getfield(REPL, Symbol("##28#29")){REPL.REPLBackend})()
358 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117; macro expansion
358 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85; eval_user_input(::Any, ::REPL.REPLBackend)
358 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
358 ./boot.jl:319; eval(::Module, ::Any)
358 /home/schmrlng/code/oss/julia-master/src/builtins.c:622; jl_toplevel_eval_in
358 /home/schmrlng/code/oss/julia-master/src/toplevel.c:765; jl_toplevel_eval_flex
358 /home/schmrlng/code/oss/julia-master/src/toplevel.c:812; jl_toplevel_eval_flex
358 /home/schmrlng/code/oss/julia-master/src/gf.c:1841; jl_fptr_trampoline
297 ./none:0; top-level scope
297 ./util.jl:156; top-level scope
297 ...e/oss/julia-master/usr/share/julia/stdlib/v1.1/Profile/src/Profile.jl:25; macro expansion
297 ./REPL[4]:1; h()
293 ./REPL[3]:1; g()
2 /home/schmrlng/code/oss/julia-master/src/gc.c:941; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:998; jl_gc_pool_alloc
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
2 /home/schmrlng/code/oss/julia-master/src/gf.c:39; jl_invoke
268 unknown stackframe
229 ./REPL[3]:1; #g#4(::Rational{Int64}, ::Function)
191 ./none:0; #f
32 /home/schmrlng/code/oss/julia-master/src/gc.c:941; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:953; jl_gc_pool_alloc
32 /home/schmrlng/code/oss/julia-master/src/gc.c:955; jl_gc_pool_alloc
32 /home/schmrlng/code/oss/julia-master/src/gc.c:2638; jl_gc_collect
2 /home/schmrlng/code/oss/julia-master/src/gc.c:2472; _jl_gc_collect
2 /home/schmrlng/code/oss/julia-master/src/gc.c:2277; mark_roots
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1483; gc_mark_queue_obj
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1430; gc_try_setmark
7 /home/schmrlng/code/oss/julia-master/src/gc.c:2473; _jl_gc_collect
3 /home/schmrlng/code/oss/julia-master/src/gc.c:1809; gc_mark_loop
3 /home/schmrlng/code/oss/julia-master/src/gc.c:1521; gc_mark_scan_objarray
3 /home/schmrlng/code/oss/julia-master/src/gc.c:1430; gc_try_setmark
3 /home/schmrlng/code/oss/julia-master/src/gc.c:1874; gc_mark_loop
3 /home/schmrlng/code/oss/julia-master/src/gc.c:1430; gc_try_setmark
1 /home/schmrlng/code/oss/julia-master/src/gc.c:2035; gc_mark_loop
1 /home/schmrlng/code/oss/julia-master/src/gc.c:2567; _jl_gc_collect
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1222; gc_sweep_other
1 /home/schmrlng/code/oss/julia-master/src/gc.c:887; sweep_malloced_arrays
22 /home/schmrlng/code/oss/julia-master/src/gc.c:2570; _jl_gc_collect
22 /home/schmrlng/code/oss/julia-master/src/gc.c:1284; gc_sweep_pool
22 /home/schmrlng/code/oss/julia-master/src/gc.c:1209; sweep_pool_pagetable
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1173; sweep_pool_pagetable1
21 /home/schmrlng/code/oss/julia-master/src/gc.c:1180; sweep_pool_pagetable1
21 /home/schmrlng/code/oss/julia-master/src/gc.c:1160; sweep_pool_pagetable0
21 /home/schmrlng/code/oss/julia-master/src/gc.c:1140; sweep_pool_page
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1035; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:912; reset_page
1 /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71; memset
1 /home/schmrlng/code/oss/julia-master/src/gc.c:915; reset_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1054; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.h:388; page_pfl_beg
13 /home/schmrlng/code/oss/julia-master/src/gc.c:1072; sweep_page
5 /home/schmrlng/code/oss/julia-master/src/gc.c:1078; sweep_page
9 /home/schmrlng/code/oss/julia-master/src/gc.c:959; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:982; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.h:383; gc_page_data
16 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
2 /home/schmrlng/code/oss/julia-master/src/gf.c:41; jl_invoke
87 unknown stackframe
10 ./REPL[2]:1; #f#3(::Rational{Int64}, ::Function)
1 /home/schmrlng/code/oss/julia-master/src/gc.c:945; jl_gc_pool_alloc
28 /home/schmrlng/code/oss/julia-master/src/gc.c:953; jl_gc_pool_alloc
3 /home/schmrlng/code/oss/julia-master/src/gc.c:979; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:987; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.h:436; page_metadata
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
5 /home/schmrlng/code/oss/julia-master/src/gc.c:945; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:959; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:965; jl_gc_pool_alloc
5 /home/schmrlng/code/oss/julia-master/src/gc.c:982; jl_gc_pool_alloc
5 /home/schmrlng/code/oss/julia-master/src/gc.h:383; gc_page_data
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
4 ./range.jl:567; iterate
4 ./int.jl:49; <
3 /home/schmrlng/code/oss/julia-master/src/gc.c:2659;
46 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gf.c:2198;
11 unknown stackframe
1 ./REPL[3]:1; #g#4(::Rational{Int64}, ::Function)
6 ./REPL[3]:1; g()
2 /home/schmrlng/code/oss/julia-master/src/gc.c:941; jl_gc_pool_alloc
1 unknown stackframe
julia> @noinline g(; a=1//2) = f(a=a)
g (generic function with 1 method)
julia> h(); Profile.clear(); @time @profile h(); Profile.print(C=true)
0.173897 seconds (20.00 M allocations: 610.352 MiB, 15.97% gc time)
173 /home/schmrlng/code/oss/julia-master/src/task.c:271; start_task
173 /home/schmrlng/code/oss/julia-master/src/julia.h:1558; jl_apply
173 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
173 ./task.jl:259; (::getfield(REPL, Symbol("##28#29")){REPL.REPLBackend})()
173 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117; macro expansion
173 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85; eval_user_input(::Any, ::REPL.REPLBackend)
173 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
173 ./boot.jl:319; eval(::Module, ::Any)
173 /home/schmrlng/code/oss/julia-master/src/builtins.c:622; jl_toplevel_eval_in
173 /home/schmrlng/code/oss/julia-master/src/toplevel.c:765; jl_toplevel_eval_flex
173 /home/schmrlng/code/oss/julia-master/src/toplevel.c:812; jl_toplevel_eval_flex
173 /home/schmrlng/code/oss/julia-master/src/gf.c:1841; jl_fptr_trampoline
161 ./none:0; top-level scope
161 ./util.jl:156; top-level scope
161 ...e/oss/julia-master/usr/share/julia/stdlib/v1.1/Profile/src/Profile.jl:25; macro expansion
161 ./REPL[4]:1; h()
158 ./REPL[6]:1; g()
3 /home/schmrlng/code/oss/julia-master/src/gc.c:941; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:967; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.h:383; gc_page_data
1 /home/schmrlng/code/oss/julia-master/src/gc.c:972; jl_gc_pool_alloc
2 /home/schmrlng/code/oss/julia-master/src/gc.c:978; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1000; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gf.c:41; jl_invoke
111 unknown stackframe
33 ./REPL[6]:1; #g#5(::Rational{Int64}, ::Function)
20 ./none:0; #f
8 ./REPL[2]:1; #f#3(::Rational{Int64}, ::Function)
2 /home/schmrlng/code/oss/julia-master/src/gc.c:953; jl_gc_pool_alloc
28 /home/schmrlng/code/oss/julia-master/src/gc.c:955; jl_gc_pool_alloc
28 /home/schmrlng/code/oss/julia-master/src/gc.c:2638; jl_gc_collect
2 /home/schmrlng/code/oss/julia-master/src/gc.c:2567; _jl_gc_collect
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1222; gc_sweep_other
2 /home/schmrlng/code/oss/julia-master/src/gc.c:888; sweep_malloced_arrays
26 /home/schmrlng/code/oss/julia-master/src/gc.c:2570; _jl_gc_collect
26 /home/schmrlng/code/oss/julia-master/src/gc.c:1284; gc_sweep_pool
26 /home/schmrlng/code/oss/julia-master/src/gc.c:1209; sweep_pool_pagetable
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1173; sweep_pool_pagetable1
25 /home/schmrlng/code/oss/julia-master/src/gc.c:1180; sweep_pool_pagetable1
25 /home/schmrlng/code/oss/julia-master/src/gc.c:1160; sweep_pool_pagetable0
25 /home/schmrlng/code/oss/julia-master/src/gc.c:1140; sweep_pool_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1035; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:915; reset_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1054; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.h:388; page_pfl_beg
15 /home/schmrlng/code/oss/julia-master/src/gc.c:1072; sweep_page
5 /home/schmrlng/code/oss/julia-master/src/gc.c:1078; sweep_page
2 /home/schmrlng/code/oss/julia-master/src/gc.c:1084; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:1100; sweep_page
1 /home/schmrlng/code/oss/julia-master/src/gc.c:959; jl_gc_pool_alloc
5 /home/schmrlng/code/oss/julia-master/src/gc.c:964; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:965; jl_gc_pool_alloc
3 /home/schmrlng/code/oss/julia-master/src/gc.c:983; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.c:987; jl_gc_pool_alloc
1 /home/schmrlng/code/oss/julia-master/src/gc.h:432; page_metadata
3 ./range.jl:567; iterate
3 ./int.jl:49; <
12 unknown stackframe
1 ./REPL[6]:1; #g#5(::Rational{Int64}, ::Function)
3 ./REPL[6]:1; g()
julia> g(; a=1//2) = f(a=a)
g (generic function with 1 method)
julia> h(); Profile.clear(); @time @profile h(); Profile.print(C=true)
0.026552 seconds
26 /home/schmrlng/code/oss/julia-master/src/task.c:271; start_task
26 /home/schmrlng/code/oss/julia-master/src/julia.h:1558; jl_apply
26 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
26 ./task.jl:259; (::getfield(REPL, Symbol("##28#29")){REPL.REPLBackend})()
26 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117; macro expansion
26 ...hmrlng/code/oss/julia-master/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85; eval_user_input(::Any, ::REPL.REPLBackend)
26 /home/schmrlng/code/oss/julia-master/src/gf.c:2196; jl_apply_generic
26 ./boot.jl:319; eval(::Module, ::Any)
26 /home/schmrlng/code/oss/julia-master/src/builtins.c:622; jl_toplevel_eval_in
26 /home/schmrlng/code/oss/julia-master/src/toplevel.c:765; jl_toplevel_eval_flex
26 /home/schmrlng/code/oss/julia-master/src/toplevel.c:812; jl_toplevel_eval_flex
26 /home/schmrlng/code/oss/julia-master/src/gf.c:1841; jl_fptr_trampoline
24 ./none:0; top-level scope
24 ./util.jl:156; top-level scope
24 ...e/oss/julia-master/usr/share/julia/stdlib/v1.1/Profile/src/Profile.jl:25; macro expansion
24 ./REPL[4]:1; h()
24 ./REPL[8]:1; g()
2 unknown stackframe Redefining |
It's very low priority for me, but this is still an issue with the 1.0.1 RC. Maybe someone with write access can add the "performance" label to keep this issue from getting lost? |
This case appears to be fixed in 1.1.1 and 1.2.0-rc2.0; 1.2.0-rc2.0 benchmarks a bit slower but that's only because it actually respects the | | |_| | | | (_| | | Version 1.1.1 (2019-05-16)
_/ |\__'_|_|_|\__'_| |
|__/ |
julia> versioninfo()
Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
julia> using BenchmarkTools
julia> @noinline f(; a=1) = a
f (generic function with 1 method)
julia> g(; a=1//2) = f(a=a)
g (generic function with 1 method)
julia> @benchmark g()
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.452 ns (0.00% GC)
median time: 1.698 ns (0.00% GC)
mean time: 1.886 ns (0.00% GC)
maximum time: 31.025 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @code_native g()
.text
; ┌ @ REPL[4]:1 within `g'
movabsq $140648840456872, %rax # imm = 0x7FEB5C2C6AA8
vmovups (%rax), %xmm0
vmovups %xmm0, (%rdi)
movq %rdi, %rax
retq
nopw %cs:(%rax,%rax)
; └ | | |_| | | | (_| | | Version 1.2.0-rc2.0 (2019-07-08)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> versioninfo()
Julia Version 1.2.0-rc2.0
Commit 9248bf7687 (2019-07-08 19:42 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
julia> using BenchmarkTools
julia> @noinline f(; a=1) = a
f (generic function with 1 method)
julia> g(; a=1//2) = f(a=a)
g (generic function with 1 method)
julia> @benchmark g()
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 2.529 ns (0.00% GC)
median time: 3.077 ns (0.00% GC)
mean time: 3.316 ns (0.00% GC)
maximum time: 33.103 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
julia> @code_native g()
.text
; ┌ @ REPL[4]:1 within `g'
pushq %rbx
subq $16, %rsp
movq %rdi, %rbx
; │┌ @ REPL[4]:1 within `#g#4'
; ││┌ @ none within `#f'
movabsq $140334513157312, %rsi # imm = 0x7FA22CCE74C0
movabsq $"#f#3", %rax
movq %rsp, %rdi
callq *%rax
; │└└
vmovups (%rsp), %xmm0
vmovups %xmm0, (%rbx)
movq %rbx, %rax
addq $16, %rsp
popq %rbx
retq
nopw %cs:(%rax,%rax)
; └ |
Reminiscent of #28342 and #28683, but I'm not sure if it's the same root cause:
The text was updated successfully, but these errors were encountered: