Skip to content

Commit

Permalink
Merge pull request #726 from gridap/no_explicit_inline
Browse files Browse the repository at this point in the history
Improve compile time (dramatically in some cases) by removing `@inline` statements
  • Loading branch information
fverdugo authored Dec 2, 2021
2 parents 901369e + 681010d commit 7f5f15e
Show file tree
Hide file tree
Showing 35 changed files with 227 additions and 222 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Improving compile times by removing unnecessary `@inline` statements. Since PR [#726](https://github.com/gridap/Gridap.jl/pull/726).

## [0.17.6] - 2021-12-01

### Added
Expand Down
6 changes: 3 additions & 3 deletions src/Arrays/AlgebraMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ function return_cache(::typeof(*),a::AbstractArray{<:Number},b::AbstractArray{<:
CachedArray(c)
end

@inline function evaluate!(cache,::typeof(*),a::AbstractMatrix{<:Number},b::AbstractVector{<:Number})
function evaluate!(cache,::typeof(*),a::AbstractMatrix{<:Number},b::AbstractVector{<:Number})
m = size(a,1)
setsize!(cache,(m,))
c = cache.array
mul!(c,a,b)
c
end

@inline function evaluate!(cache,::typeof(*),a::AbstractMatrix{<:Number},b::AbstractMatrix{<:Number})
function evaluate!(cache,::typeof(*),a::AbstractMatrix{<:Number},b::AbstractMatrix{<:Number})
m = size(a,1)
n = size(b,2)
setsize!(cache,(m,n))
Expand All @@ -31,7 +31,7 @@ function return_cache(k::MulAddMap,a,b,c)
CachedArray(d)
end

@inline function evaluate!(cache,k::MulAddMap,a,b,c)
function evaluate!(cache,k::MulAddMap,a,b,c)
setsize!(cache,size(c))
d = cache.array
copyto!(d,c)
Expand Down
2 changes: 1 addition & 1 deletion src/Arrays/CachedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function setsize!(a::CachedArray{T,N},s::NTuple{N,Int}) where {T,N}
end
end

@inline function setsize!(a::CachedArray{T,N},s::NTuple{N,<:Integer}) where {T,N}
function setsize!(a::CachedArray{T,N},s::NTuple{N,<:Integer}) where {T,N}
_s::NTuple{N,Int} = s
setsize!(a,_s)
end
Expand Down
2 changes: 1 addition & 1 deletion src/Arrays/IdentityVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct IdentityVector{T<:Integer} <: AbstractVector{T}
length::T
end

@inline function getindex(c::IdentityVector{T},i::Integer) where T
function getindex(c::IdentityVector{T},i::Integer) where T
@check i > 0
@check i <= c.length
j::T = i
Expand Down
20 changes: 10 additions & 10 deletions src/Arrays/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ end
```
"""
@inline getindex!(cache,a::AbstractArray,i...) = a[i...]
@inline getindex!(cache,a::AbstractArray,i::CartesianIndex) = getindex!(cache,a,Tuple(i)...)
@inline getindex!(cache,a::AbstractArray,i::Integer) = _getindex_1d!(IndexStyle(a),cache,a,i)
@inline function getindex!(cache,a::AbstractArray{T,N},i::Vararg{Integer,N}) where {T,N}
getindex!(cache,a::AbstractArray,i...) = a[i...]
getindex!(cache,a::AbstractArray,i::CartesianIndex) = getindex!(cache,a,Tuple(i)...)
getindex!(cache,a::AbstractArray,i::Integer) = _getindex_1d!(IndexStyle(a),cache,a,i)
function getindex!(cache,a::AbstractArray{T,N},i::Vararg{Integer,N}) where {T,N}
_getindex_nd!(IndexStyle(a),cache,a,CartesianIndex(i))
end
@inline _getindex_1d!(s::IndexLinear,cache,a,i) = a[i]
@inline _getindex_1d!(s::IndexCartesian,cache,a,i) = _getindex_nd!(s,cache,a,CartesianIndices(a)[i])
@inline _getindex_nd!(s::IndexLinear,cache,a,i) = _getindex_1d!(s,cache,a,LinearIndices(a)[i])
@inline _getindex_nd!(s::IndexCartesian,cache,a,i) = a[i]
_getindex_1d!(s::IndexLinear,cache,a,i) = a[i]
_getindex_1d!(s::IndexCartesian,cache,a,i) = _getindex_nd!(s,cache,a,CartesianIndices(a)[i])
_getindex_nd!(s::IndexLinear,cache,a,i) = _getindex_1d!(s,cache,a,LinearIndices(a)[i])
_getindex_nd!(s::IndexCartesian,cache,a,i) = a[i]

"""
array_cache(a::AbstractArray)
Expand Down Expand Up @@ -161,8 +161,8 @@ This function is used to compute [`testitem`](@ref) for 0-length arrays.
"""
function testvalue end

@inline testvalue(::Type{T}) where T = zero(T)
@inline testvalue(v) = testvalue(typeof(v))
testvalue(::Type{T}) where T = zero(T)
testvalue(v) = testvalue(typeof(v))

function testvalue(::Type{T}) where T<:AbstractArray{E,N} where {E,N}
similar(T,tfill(0,Val(N))...)
Expand Down
30 changes: 15 additions & 15 deletions src/Arrays/LazyArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function lazy_map(k,f::AbstractArray...)
lazy_map(k,T,f...)
end

#@inline lazy_map(::typeof(evaluate),k::AbstractArray,f::AbstractArray...) = LazyArray(k,f...)
#lazy_map(::typeof(evaluate),k::AbstractArray,f::AbstractArray...) = LazyArray(k,f...)

# This is the function to be overload to specialize on the Map f
"""
Expand All @@ -67,13 +67,13 @@ end
Like [`lazy_map(f,a::AbstractArray...)`](@ref), but the user provides the element type
of the resulting array in order to circumvent type inference.
"""
@inline function lazy_map(k,T::Type,f::AbstractArray...)
function lazy_map(k,T::Type,f::AbstractArray...)
s = _common_size(f...)
lazy_map(evaluate,T,Fill(k, s), f...)
end

# This is the function to be overload to specialize on the array types
@inline function lazy_map(::typeof(evaluate),T::Type,k::AbstractArray,f::AbstractArray...)
function lazy_map(::typeof(evaluate),T::Type,k::AbstractArray,f::AbstractArray...)
s = _common_size(k,f...)
N = length(s)
LazyArray(T,Val(N),k,f...)
Expand Down Expand Up @@ -193,7 +193,7 @@ function _array_cache!(dict::Dict,a::LazyArray)
(cg, cgi, cf), IndexItemPair(index, item)
end

@inline function getindex!(cache, a::LazyArray, i::Integer)
function getindex!(cache, a::LazyArray, i::Integer)
_cache, index_and_item = cache
index = LinearIndices(a)[i]
if index_and_item.index != index
Expand All @@ -205,7 +205,7 @@ end
index_and_item.item
end

@inline function getindex!(cache, a::LazyArray{G,T,N}, i::Vararg{Integer,N}) where {G,T,N}
function getindex!(cache, a::LazyArray{G,T,N}, i::Vararg{Integer,N}) where {G,T,N}
_cache, index_and_item = cache
index = LinearIndices(a)[i...]
if index_and_item.index != index
Expand All @@ -217,7 +217,7 @@ end
index_and_item.item
end

@inline function _getindex_and_call!(cgi,gi,cf,args,i...)
function _getindex_and_call!(cgi,gi,cf,args,i...)
fi = map((cj,fj) -> getindex!(cj,fj,i...),cf,args)
evaluate!(cgi, gi, fi...)
end
Expand Down Expand Up @@ -322,33 +322,33 @@ end
# see https://discourse.julialang.org/t/performance-depends-dramatically-on-compilation-order/58425
# Hopefully, they can be removed in the future

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any},i...)
f1 = getindex!(cf[1],args[1],i...)
evaluate!(cgi,gi,f1)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
evaluate!(cgi,gi,f1,f2)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
evaluate!(cgi,gi,f1,f2,f3)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
f4 = getindex!(cf[4],args[4],i...)
evaluate!(cgi,gi,f1,f2,f3,f4)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
Expand All @@ -357,7 +357,7 @@ end
evaluate!(cgi,gi,f1,f2,f3,f4,f5)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
Expand All @@ -367,7 +367,7 @@ end
evaluate!(cgi,gi,f1,f2,f3,f4,f5,f6)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
Expand All @@ -378,7 +378,7 @@ end
evaluate!(cgi,gi,f1,f2,f3,f4,f5,f6,f7)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
Expand All @@ -390,7 +390,7 @@ end
evaluate!(cgi,gi,f1,f2,f3,f4,f5,f6,f7,f8)
end

@inline function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any,Any,Any},i...)
function _getindex_and_call!(cgi,gi,cf,args::Tuple{Any,Any,Any,Any,Any,Any,Any,Any,Any},i...)
f1 = getindex!(cf[1],args[1],i...)
f2 = getindex!(cf[2],args[2],i...)
f3 = getindex!(cf[3],args[3],i...)
Expand Down
16 changes: 8 additions & 8 deletions src/Arrays/Maps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ end

return_cache(f::Broadcasting,x...) = nothing

@inline evaluate!(cache,f::Broadcasting,x...) = broadcast(f.f,x...)
evaluate!(cache,f::Broadcasting,x...) = broadcast(f.f,x...)

function return_value(f::Broadcasting,x...)
broadcast( (y...) -> f.f(testargs(f.f,y...)...), x... )
end

@inline function evaluate!(cache,f::Broadcasting,x::Union{Number,AbstractArray{<:Number}}...)
function evaluate!(cache,f::Broadcasting,x::Union{Number,AbstractArray{<:Number}}...)
r = _prepare_cache!(cache,x...)
a = r.array
broadcast!(f.f,a,x...)
a
end

@inline function evaluate!(cache,f::Broadcasting,x::AbstractArray{<:Number})
function evaluate!(cache,f::Broadcasting,x::AbstractArray{<:Number})
setsize!(cache,size(x))
a = cache.array
@inbounds for i in eachindex(x)
Expand Down Expand Up @@ -198,7 +198,7 @@ function return_cache(f::Broadcasting,x::Union{Number,AbstractArray{<:Number}}..
cache
end

@inline function _prepare_cache!(c,x...)
function _prepare_cache!(c,x...)
s = map(_size,x)
bs = Base.Broadcast.broadcast_shape(s...)
if bs != size(c)
Expand All @@ -207,8 +207,8 @@ end
c
end

@inline _size(a) = size(a)
@inline _size(a::Number) = (1,)
_size(a) = size(a)
_size(a::Number) = (1,)

"""
OperationMap(f,args)
Expand All @@ -221,7 +221,7 @@ That is, `OperationMap(f,args)(x...)` is formally defined as
struct OperationMap{K,L} <: Map
k::K
l::L
@inline function OperationMap(k,l)
function OperationMap(k,l)
new{typeof(k),typeof(l)}(k,l)
end
end
Expand All @@ -233,7 +233,7 @@ function return_cache(c::OperationMap,x...)
ck, cl
end

@inline function evaluate!(cache,c::OperationMap,x...)
function evaluate!(cache,c::OperationMap,x...)
ck, cf = cache
lx = map((ci,fi) -> evaluate!(ci,fi,x...),cf,c.l)
evaluate!(ck,c.k,lx...)
Expand Down
4 changes: 2 additions & 2 deletions src/Arrays/PosNegReindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ function return_cache(k::PosNegReindex,i::Integer)
c_p, c_n
end

@inline function evaluate!(cache,k::PosNegReindex,i::Integer)
function evaluate!(cache,k::PosNegReindex,i::Integer)
c_p, c_n = cache
i>0 ? getindex!(c_p,k.values_pos,i) : getindex!(c_n,k.values_neg,-i)
end

@inline function evaluate(k::PosNegReindex,i::Integer)
function evaluate(k::PosNegReindex,i::Integer)
i>0 ? k.values_pos[i] : k.values_neg[-i]
end

Expand Down
4 changes: 2 additions & 2 deletions src/Arrays/Reindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function return_value(k::Reindex,i...)
length(k.values)!=0 ? evaluate(k,testargs(k,i...)...) : testitem(k.values)
end
return_cache(k::Reindex,i...) = array_cache(k.values)
@inline evaluate!(cache,k::Reindex,i...) = getindex!(cache,k.values,i...)
@inline evaluate(k::Reindex,i...) = k.values[i...]
evaluate!(cache,k::Reindex,i...) = getindex!(cache,k.values,i...)
evaluate(k::Reindex,i...) = k.values[i...]

#"""
# reindex(i_to_v::AbstractArray, j_to_i::AbstractArray)
Expand Down
8 changes: 4 additions & 4 deletions src/CellData/AttachConstraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Arrays.return_cache(k::ConstrainRowsMap,array,constr,mask)
return_cache(*,constr,array)
end

@inline function Arrays.evaluate!(cache,k::ConstrainRowsMap,array,constr,mask)
function Arrays.evaluate!(cache,k::ConstrainRowsMap,array,constr,mask)
if mask
evaluate!(cache,*,constr,array)
else
Expand All @@ -29,7 +29,7 @@ function Arrays.return_cache(k::ConstrainRowsMap,matvec::Tuple,constr,mask)
(cmat,cvec)
end

@inline function Arrays.evaluate!(cache,k::ConstrainRowsMap,matvec::Tuple,constr,mask)
function Arrays.evaluate!(cache,k::ConstrainRowsMap,matvec::Tuple,constr,mask)
if mask
cmat, cvec = cache
mat, vec = matvec
Expand All @@ -47,7 +47,7 @@ function Arrays.return_cache(k::ConstrainColsMap,array,constr_t,mask)
return_cache(*,array,constr_t)
end

@inline function Arrays.evaluate!(cache,k::ConstrainColsMap,array,constr_t,mask)
function Arrays.evaluate!(cache,k::ConstrainColsMap,array,constr_t,mask)
if mask
evaluate!(cache,*,array,constr_t)
else
Expand All @@ -60,7 +60,7 @@ function Arrays.return_cache(k::ConstrainColsMap,matvec::Tuple,constr_t,mask)
return_cache(k,mat,constr_t,mask)
end

@inline function Arrays.evaluate!(cache,k::ConstrainColsMap,matvec::Tuple,constr_t,mask)
function Arrays.evaluate!(cache,k::ConstrainColsMap,matvec::Tuple,constr_t,mask)
if mask
mat, vec = matvec
_mat = evaluate!(cache,k,mat,constr_t,mask)
Expand Down
4 changes: 2 additions & 2 deletions src/CellData/AttachDirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Arrays.return_cache(k::AttachDirichletMap,matvec::Tuple,vals,mask)
return_cache(k.muladd,mat,vals,vec)
end

@inline function Arrays.evaluate!(cache,k::AttachDirichletMap,matvec::Tuple,vals,mask)
function Arrays.evaluate!(cache,k::AttachDirichletMap,matvec::Tuple,vals,mask)
if mask
mat, vec = matvec
vec_with_bcs = evaluate!(cache,k.muladd,mat,vals,vec)
Expand All @@ -79,7 +79,7 @@ function Arrays.return_cache(k::AttachDirichletMap,mat,vals,mask)
(cm,cv)
end

@inline function Arrays.evaluate!(cache,k::AttachDirichletMap,mat,vals,mask)
function Arrays.evaluate!(cache,k::AttachDirichletMap,mat,vals,mask)
cm, cv = cache
if mask
vec_with_bcs = evaluate!(cm,*,mat,vals)
Expand Down
6 changes: 3 additions & 3 deletions src/CellData/CellStates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ end
end
end

@inline function _update_states!(b,q,states,::Val{i}) where i
function _update_states!(b,q,states,::Val{i}) where i
_update_state!(b,q,states,Val{i}())
_update_states!(b,q,states,Val{i-1}())
nothing
end

@inline function _update_states!(b,q,states,::Val{0})
function _update_states!(b,q,states,::Val{0})
nothing
end

@inline function _update_state!(b,q,states,::Val{i}) where i
function _update_state!(b,q,states,::Val{i}) where i
b[i][q] = states[i]
nothing
end
Loading

0 comments on commit 7f5f15e

Please sign in to comment.