Skip to content

Commit

Permalink
fix a performance regression due to the GlobalRef change (7908246)
Browse files Browse the repository at this point in the history
this was mostly evident in the go_benchmark perf test

also strip empty metadata nodes from inlined functions to save space
  • Loading branch information
JeffBezanson committed Jul 12, 2015
1 parent d0c35a1 commit 315fc50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1974,17 +1974,6 @@ function exprtype(x::ANY, sv::StaticVarInfo)
end
end

function without_linenums(a::Array{Any,1})
l = []
for x in a
if (isa(x,Expr) && is(x.head,:line)) || isa(x,LineNumberNode)
else
push!(l, x)
end
end
l
end

# known affect-free calls (also effect-free)
const _pure_builtins = Any[tuple, svec, fieldtype, apply_type, is, isa, typeof, typeassert]

Expand Down Expand Up @@ -2032,6 +2021,10 @@ function effect_free(e::ANY, sv, allow_volatile::Bool)
isa(e,TopNode) || isa(e,QuoteNode) || isa(e,Type) || isa(e,Tuple)
return true
end
if isa(e,GlobalRef)
allow_volatile && return true
return isconst(e.mod, e.name)
end
if isconstantfunc(e, sv) !== false
return true
end
Expand Down Expand Up @@ -2248,7 +2241,8 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
end

body = Expr(:block)
body.args = without_linenums(ast.args[3].args)::Array{Any,1}
body.args = filter(x->!((isa(x,Expr) && is(x.head,:line)) || isa(x,LineNumberNode)),
ast.args[3].args::Array{Any,1})
cost::Int = 1000
if incompletematch
cost *= 4
Expand Down Expand Up @@ -2284,6 +2278,9 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
return NF
end
end
# remove empty meta
body.args = filter(x->!(isa(x,Expr) && x.head === :meta && isempty(x.args)),
body.args)

spnames = Any[ sp[i].name for i=1:2:length(sp) ]
enc_vinflist = enclosing_ast.args[2][1]::Array{Any,1}
Expand Down
8 changes: 4 additions & 4 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ static void mark_volatile_vars(jl_array_t *stmts, std::map<jl_sym_t*,jl_varinfo_

static bool expr_is_symbol(jl_value_t *e)
{
return (jl_is_symbol(e) || jl_is_symbolnode(e) || jl_is_topnode(e));
return (jl_is_symbol(e) || jl_is_symbolnode(e) || jl_is_topnode(e) || jl_is_globalref(e));
}

// a very simple, conservative escape analysis that is sufficient for
Expand Down Expand Up @@ -1746,7 +1746,8 @@ static bool is_stable_expr(jl_value_t *ex, jl_codectx_t *ctx)
static bool might_need_root(jl_value_t *ex)
{
return (!jl_is_symbol(ex) && !jl_is_symbolnode(ex) && !jl_is_gensym(ex) &&
!jl_is_bool(ex) && !jl_is_quotenode(ex) && !jl_is_byte_string(ex));
!jl_is_bool(ex) && !jl_is_quotenode(ex) && !jl_is_byte_string(ex) &&
!jl_is_globalref(ex));
}

static Value *emit_boxed_rooted(jl_value_t *e, jl_codectx_t *ctx)
Expand Down Expand Up @@ -4379,8 +4380,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
vi.hasGCRoot = false;
continue;
}
if (vi.isSA && !vi.isVolatile &&
!vi.isCaptured && !vi.usedUndef) {
if (vi.isSA && !vi.isVolatile && !vi.isCaptured && !vi.usedUndef) {
vi.hasGCRoot = false; // so far...
}
else {
Expand Down

0 comments on commit 315fc50

Please sign in to comment.