# Be less aware of when Julia avoids specializing?

**URL:** <https://discourse.julialang.org/t/be-less-aware-of-when-julia-avoids-specializing/109111>\
**Category:** Internals & Design\
**Created:** [January 22, 2024, 5:25pm UTC](https://discourse.julialang.org/t/be-less-aware-of-when-julia-avoids-specializing/109111 "2024-01-22T17:25:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [January 22, 2024, 8:50pm UTC](https://discourse.julialang.org/t/be-less-aware-of-when-julia-avoids-specializing/109111/2 "2024-01-22T20:50:26Z")

</div>

+1

Or at least having much more sensible defaults given the current state of Julia precompilation and package extensions. I could see having a larger upper bound for `Vararg` non-specialization be an easy improvement. Right now it seems too extreme imo:

```julia
julia> f(x...) = x

julia> Base.specializations(@which f(1, 2))
Base.MethodSpecializations(MethodInstance for f(::Int64, ::Vararg{Int64}))

```

which is not great when, as you mention, it’s often encouraged to write generic code without worrying about lost performance.

Also worth noting that the `Vararg` specialization rules are currently so complicated they seem to result in unexpected behavior when you combine them with other non-specializing types:

> [@Specialization on vararg of types](https://discourse.julialang.org/t/specialization-on-vararg-of-types/108251/7):
>
> I don’t know if it was left out for some good reason, but the Vararg section is actually pretty vague about what is being specialized. Unlike lone functions and types, Vararg specifies multiple types with a possibly fixed arity. From what I could tell (though you should probably verify yourself), the “nonspecializing” \_\_(x::Int...) specializes on Int just fine, it’s the arity it gives up on. Even \_\_(x...) specializes on the first argument’s type in 2 specializations, one where the rest of the t…

I think simpler rules would generally be better if the specialization behavior is changed.

---

_[View the full topic](https://discourse.julialang.org/t/be-less-aware-of-when-julia-avoids-specializing/109111)._
