{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/28087","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/28087/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/28087/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/28087/events","html_url":"https://github.com/JuliaLang/julia/issues/28087","id":340762013,"node_id":"MDU6SXNzdWUzNDA3NjIwMTM=","number":28087,"title":"allocations when performing no-op convert on struct instance with Union fieldtype","user":{"login":"jrevels","id":3277443,"node_id":"MDQ6VXNlcjMyNzc0NDM=","avatar_url":"https://avatars2.githubusercontent.com/u/3277443?v=4","gravatar_id":"","url":"https://api.github.com/users/jrevels","html_url":"https://github.com/jrevels","followers_url":"https://api.github.com/users/jrevels/followers","following_url":"https://api.github.com/users/jrevels/following{/other_user}","gists_url":"https://api.github.com/users/jrevels/gists{/gist_id}","starred_url":"https://api.github.com/users/jrevels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrevels/subscriptions","organizations_url":"https://api.github.com/users/jrevels/orgs","repos_url":"https://api.github.com/users/jrevels/repos","events_url":"https://api.github.com/users/jrevels/events{/privacy}","received_events_url":"https://api.github.com/users/jrevels/received_events","type":"User","site_admin":false},"labels":[{"id":183231688,"node_id":"MDU6TGFiZWwxODMyMzE2ODg=","url":"https://api.github.com/repos/JuliaLang/julia/labels/codegen","name":"codegen","color":"d4c5f9","default":false},{"id":115858,"node_id":"MDU6TGFiZWwxMTU4NTg=","url":"https://api.github.com/repos/JuliaLang/julia/labels/performance","name":"performance","color":"d7e102","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-12T19:07:51Z","updated_at":"2018-10-18T02:01:01Z","closed_at":null,"author_association":"MEMBER","body":"There might be a better MWE for this, I'm not sure why it happens (codegen perf bug, I'm guessing?):\r\n\r\n```julia\r\njulia> using BenchmarkTools\r\n\r\njulia> struct FooA{X}\r\n           x::X\r\n       end\r\n\r\njulia> F, f = FooA{Int}, FooA{Int}(1)\r\n(FooA{Int64}, FooA{Int64}(1))\r\n\r\njulia> @btime convert($F, $f)\r\n  0.035 ns (0 allocations: 0 bytes)\r\nFooA{Int64}(1)\r\n\r\njulia> @code_lowered convert(F, f)\r\nCodeInfo(\r\n123 1 ─     return %%x                                                                                            │\r\n)\r\n\r\njulia> @code_llvm convert(F, f)\r\n\r\n; Function convert\r\n; Location: essentials.jl:123\r\ndefine { i64 } @julia_convert_32884(%jl_value_t addrspace(10)*, { i64 } addrspace(11)* nocapture nonnull readonly dereferenceable(8)) {\r\ntop:\r\n  %2 = getelementptr inbounds { i64 }, { i64 } addrspace(11)* %1, i64 0, i32 0\r\n  %.unpack = load i64, i64 addrspace(11)* %2, align 8\r\n  %3 = insertvalue { i64 } undef, i64 %.unpack, 0\r\n  ret { i64 } %3\r\n}\r\n\r\njulia> struct FooB{X}\r\n           x::Union{X,Nothing}\r\n       end\r\n\r\njulia> F, f = FooB{Int}, FooB{Int}(1)\r\n(FooB{Int64}, FooB{Int64}(1))\r\n\r\njulia> @btime convert($F, $f)\r\n  56.547 ns (2 allocations: 64 bytes)\r\nFooB{Int64}(1)\r\n\r\njulia> @code_lowered convert(F, f)\r\nCodeInfo(\r\n123 1 ─     return %%x                                                                                            │\r\n)\r\n\r\njulia> @code_llvm convert(F, f)\r\n\r\n; Function convert\r\n; Location: essentials.jl:123\r\ndefine void @julia_convert_33024({ i64, i8 }* noalias nocapture sret, %jl_value_t addrspace(10)*, { i64, i8 } addrspace(11)* nocapture nonnull readonly dereferenceable(16)) {\r\ntop:\r\n  %3 = bitcast { i64, i8 }* %0 to i8*\r\n  %4 = bitcast { i64, i8 } addrspace(11)* %2 to i8 addrspace(11)*\r\n  call void @llvm.memcpy.p0i8.p11i8.i64(i8* %3, i8 addrspace(11)* %4, i64 16, i32 8, i1 false)\r\n  ret void\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/430849203","html_url":"https://github.com/JuliaLang/julia/issues/28087#issuecomment-430849203","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/28087","id":430849203,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDg0OTIwMw==","user":{"login":"KristofferC","id":1282691,"node_id":"MDQ6VXNlcjEyODI2OTE=","avatar_url":"https://avatars1.githubusercontent.com/u/1282691?v=4","gravatar_id":"","url":"https://api.github.com/users/KristofferC","html_url":"https://github.com/KristofferC","followers_url":"https://api.github.com/users/KristofferC/followers","following_url":"https://api.github.com/users/KristofferC/following{/other_user}","gists_url":"https://api.github.com/users/KristofferC/gists{/gist_id}","starred_url":"https://api.github.com/users/KristofferC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KristofferC/subscriptions","organizations_url":"https://api.github.com/users/KristofferC/orgs","repos_url":"https://api.github.com/users/KristofferC/repos","events_url":"https://api.github.com/users/KristofferC/events{/privacy}","received_events_url":"https://api.github.com/users/KristofferC/received_events","type":"User","site_admin":false},"created_at":"2018-10-18T02:01:01Z","updated_at":"2018-10-18T02:01:01Z","author_association":"CONTRIBUTOR","body":"The benchmark loop calls the kernel as\r\n\r\n```\r\n301 │    %18  = π (FooB{Int64}, Core.Compiler.Const(FooB{Int64}, false))                                    │\r\n    │    %19  = π (FooB{Int64}(1), Core.Compiler.Const(FooB{Int64}(1), false))                              │\r\n    │           invoke Main.:(##core#368)(%18::Type, %19::FooB{Int64})    \r\n```\r\n\r\nand my guess is that it is not getting specialized on the Type argument."}}
{"actor":{"display_login":"KristofferC"}}