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

Unexpected allocations caused by unused typevars #29393

Closed
rdeits opened this issue Sep 27, 2018 · 6 comments
Closed

Unexpected allocations caused by unused typevars #29393

rdeits opened this issue Sep 27, 2018 · 6 comments
Labels
compiler:codegen Generation of LLVM IR and native code performance Must go faster

Comments

@rdeits
Copy link
Contributor

rdeits commented Sep 27, 2018

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.0

where 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.0

Is 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)
@JeffBezanson
Copy link
Member

Was also observed here #27813 (comment) (there's a response below that). Hasn't been a high priority but I guess we can do something about it, and/or give a warning for parameters that don't appear in the signature.

@JeffBezanson JeffBezanson added performance Must go faster compiler:codegen Generation of LLVM IR and native code labels Sep 27, 2018
@nalimilan
Copy link
Member

+1 for a warning.

@Keno
Copy link
Member

Keno commented Sep 29, 2018

Might be fixed by #29323?

@JeffBezanson
Copy link
Member

No, I think it's a calling convention issue.

bors bot added a commit to CliMA/ClimaCore.jl that referenced this issue Jul 1, 2022
785: Add and fix Aqua tests r=charleskawczynski a=charleskawczynski

This PR adds [Aqua](https://github.com/JuliaTesting/Aqua.jl) tests, specifically, `Aqua.test_unbound_args(ClimaCore)`, which tests that no functions defined in ClimaCore run into [this julia issue](JuliaLang/julia#29393).

Adding this test revealed 9 instances of this issue, and the PR also includes fixes so that we pass all of the tests.

Co-authored-by: Charles Kawczynski <[email protected]>
@vtjnash
Copy link
Member

vtjnash commented Sep 22, 2022

Fixed by cfec173 #46608

@vtjnash vtjnash closed this as completed Sep 22, 2022
@KristofferC
Copy link
Member

It's funny that the commit message explicitly says that it does not fix this issue.

ranocha added a commit to ranocha/NLSolversBase.jl that referenced this issue Oct 7, 2022
I got a warning on Julia v1.8.2:

```
[ Info: Precompiling OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed]
WARNING: method definition for TwiceDifferentiable at ~/.julia/packages/NLSolversBase/cfJrN/src/objective_types/incomplete.jl:96 declares type variable TH but does not use it.
```

Unused type variables can sometimes be bad, see JuliaLang/julia#29393
bors bot added a commit to CliMA/ClimaAtmos.jl that referenced this issue Oct 7, 2022
896: Add aqua test r=charleskawczynski a=charleskawczynski

This PR adds some aqua tests
 - For unbound type parameters, see JuliaLang/julia#29393
 - For method ambiguities, see SciML/OrdinaryDiffEq.jl#1750

Co-authored-by: Charles Kawczynski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code performance Must go faster
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants