From 8973ed1f95857bce3505e7f5241dba1b5da7bb4d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 1 Aug 2014 03:34:15 -0400 Subject: [PATCH] small compiler performance improvement Inference calls eval() a lot to resolve module references, and this was inefficient since eval() assumes expressions might need to be expanded, so everything was going back through part of the front end. Fixed by calling the interpreter directly. Unfortunately this does not affect the system image build time much, only a couple of seconds. But these are worth it: time for `make testall` before: real 3m56.272s user 13m41.657s sys 0m4.517s after: real 3m6.434s user 10m52.977s sys 0m4.223s time for `using Gadfly` before: julia> tic(); using Gadfly; toc() elapsed time: 51.968993674 seconds after: julia> tic(); using Gadfly; toc() elapsed time: 48.591181748 seconds Would be great to find more low-hanging fruit like this. --- base/inference.jl | 4 +++- src/interpreter.c | 4 ++-- src/julia.h | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/base/inference.jl b/base/inference.jl index 08adbcb5af2fc..855f54138efe0 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -63,7 +63,9 @@ function _iisconst(s::Symbol) isdefined(m,s) && (ccall(:jl_is_const, Int32, (Any, Any), m, s) != 0) end -_ieval(x::ANY) = eval((inference_stack::CallStack).mod, x) +_ieval(x::ANY) = + ccall(:jl_interpret_toplevel_expr_in, Any, (Any, Any, Ptr{Void}, Csize_t), + (inference_stack::CallStack).mod, x, C_NULL, 0) _iisdefined(x::ANY) = isdefined((inference_stack::CallStack).mod, x) _iisconst(s::SymbolNode) = _iisconst(s.name) diff --git a/src/interpreter.c b/src/interpreter.c index 4587803921c9e..be4e1c6d48c7b 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -31,8 +31,8 @@ jl_value_t *jl_interpret_toplevel_expr_with(jl_value_t *e, return eval(e, locals, nl); } -jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, - jl_value_t **locals, size_t nl) +DLLEXPORT jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, + jl_value_t **locals, size_t nl) { jl_value_t *v=NULL; jl_module_t *last_m = jl_current_module; diff --git a/src/julia.h b/src/julia.h index f8bf0d89b35bc..052906bfe2db7 100644 --- a/src/julia.h +++ b/src/julia.h @@ -912,8 +912,8 @@ jl_value_t *jl_interpret_toplevel_thunk_with(jl_lambda_info_t *lam, jl_value_t *jl_interpret_toplevel_expr(jl_value_t *e); jl_value_t *jl_interpret_toplevel_expr_with(jl_value_t *e, jl_value_t **locals, size_t nl); -jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, - jl_value_t **locals, size_t nl); +DLLEXPORT jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, + jl_value_t **locals, size_t nl); int jl_is_toplevel_only_expr(jl_value_t *e); jl_module_t *jl_base_relative_to(jl_module_t *m); void jl_type_infer(jl_lambda_info_t *li, jl_tuple_t *argtypes,