- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.7k
Closed
Labels
compiler:codegenGeneration of LLVM IR and native codeGeneration of LLVM IR and native codeperformanceMust go fasterMust go faster
Description
Under some circumstances, having an unused typevar in a method definition causes the method to unexpectedly allocate and perform poorly. For example:
julia> function foo(y::T) where {N, T}
         1.0 * y
       end
foo (generic function with 1 method)
julia> using BenchmarkTools
[ Info: Recompiling stale cache file /home/BOSDYN/rdeits/.julia/compiled/v1.0/BenchmarkTools/ZXPQo.ji for BenchmarkTools [6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf]
julia> @btime foo($(1))
  13.938 ns (1 allocation: 16 bytes)
1.0where the N parameter is unused. Removing that parameter fixes the problem:
julia> function foo(y::T) where {T}
         1.0 * y
       end
foo (generic function with 1 method)
julia> @btime foo($(1))
  1.239 ns (0 allocations: 0 bytes)
1.0Is this and expected performance issue? I've observed it with Julia 1.0 and the latest nightly build.
julia> versioninfo()
Julia Version 1.0.1-pre.171
Commit 398d87829d (2018-09-26 22:52 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1535M v6 @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)CameronBieganek, NHDaly, johnnychen94, briochemc and charleskawczynski
Metadata
Metadata
Assignees
Labels
compiler:codegenGeneration of LLVM IR and native codeGeneration of LLVM IR and native codeperformanceMust go fasterMust go faster