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

a few compiler improvements #36176

Merged
merged 1 commit into from
Jun 8, 2020
Merged

a few compiler improvements #36176

merged 1 commit into from
Jun 8, 2020

Conversation

JeffBezanson
Copy link
Member

  • improve fieldtype_nothrow for vararg tuple types
  • remove UnionAll construction code from tuple_type_head
  • add specializations to avoid some common generated functions

This shaves about 0.5 sec off the TTFP. The first two items fix some disastrous code for vararg tuple conversion:

julia> code_typed(convert, (Type{Tuple{Vararg{Int}}},NTuple{2,Int8}))
1-element Array{Any,1}:
 CodeInfo(
1 ─      invoke Core.TypeVar(Symbol("#s2")::Symbol, Base.Tuple::Any)::TypeVar
│        Base.fieldtype(T, 1)::Type{Int64}
│   %3 = Base.getfield(x, 1, true)::Int8
│   %4 = Core.sext_int(Core.Int64, %3)::Int64
│   %5 = (getfield)(x, 2)::Int8
│        invoke Core.TypeVar(Symbol("#s2")::Symbol, Base.Tuple::Any)::TypeVar
│        Base.fieldtype(T, 1)::Type{Int64}
│   %8 = Core.sext_int(Core.Int64, %5)::Int64
│   %9 = Core.tuple(%4, %8)::Tuple{Int64,Int64}
└──      return %9
) => Tuple{Int64,Int64}

@JeffBezanson JeffBezanson added the compiler:latency Compiler latency label Jun 7, 2020
base/compiler/tfuncs.jl Outdated Show resolved Hide resolved
base/multidimensional.jl Outdated Show resolved Hide resolved
@timholy
Copy link
Member

timholy commented Jun 7, 2020

Worth pointing out that we might not even need those generated functions if we fix #9080.

- improve fieldtype_nothrow for vararg tuple types
- remove UnionAll construction code from tuple_type_head
- add specializations to avoid some common generated functions
return false
# If we don't know the exact type, the length of the tuple will be determined
# at runtime and we can't say anything.
return exact
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't seem right. fieldtype(NTuple{10, T} where T, 20) certainly does error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't contain a Vararg but I guess it might in the future, so I can add it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I guess we didn't change this yet.

@@ -776,6 +775,20 @@ end
end
end

# Always index with the exactly indices provided.
@generated function _unsafe_getindex!(dest::AbstractArray, src::AbstractArray, I::Vararg{Union{Real, AbstractArray}, N}) where N
_generate_unsafe_getindex!_body(N)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Keno Keno merged commit 9d4565b into master Jun 8, 2020
@Keno Keno deleted the jb/misccompilerspeed branch June 8, 2020 02:26
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
- improve fieldtype_nothrow for vararg tuple types
- remove UnionAll construction code from tuple_type_head
- add specializations to avoid some common generated functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants