From 7d6e46713fa24bf56681957c24fa6b616f3727bc Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 22 Aug 2025 11:41:24 -0600 Subject: [PATCH 1/3] In `--trace-compile` Tag nested precompiles with `# nested_compile`. ```julia ./usr/bin/julia --startup=no --trace-compile=stderr -e ' Base.@assume_effects :foldable function nested1(x) sum(collect(x for _ in 1:10_000_000)) end f1(x) = nested1(sizeof(x)) + x f1(2)' precompile(Tuple{typeof(Main.nested1), Int64}) # nested_compile precompile(Tuple{typeof(Main.f1), Int64}) ./usr/bin/julia --startup=no --trace-compile=stderr --trace-compile-timing -e ' Base.@assume_effects :foldable function nested1(x) sum(collect(x for _ in 1:10_000_000)) end f1(x) = nested1(sizeof(x)) + x f1(2)' #= 8.1 ms =# precompile(Tuple{typeof(Main.nested1), Int64}) # nested_compile #= 71.3 ms =# precompile(Tuple{typeof(Main.f1), Int64}) ``` --- src/gf.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gf.c b/src/gf.c index abe64da7a45cf..46284623044e1 100644 --- a/src/gf.c +++ b/src/gf.c @@ -3213,7 +3213,8 @@ JL_DLLEXPORT void jl_force_trace_compile_timing_disable(void) jl_atomic_fetch_add(&jl_force_trace_compile_timing_enabled, -1); } -static void record_precompile_statement(jl_method_instance_t *mi, double compilation_time, int is_recompile) +static void record_precompile_statement(jl_method_instance_t *mi, double compilation_time, + int is_recompile, int is_nested) { static ios_t f_precompile; static JL_STREAM* s_precompile = NULL; @@ -3252,6 +3253,9 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila jl_printf(s_precompile, "\e[0m"); } } + if (is_nested) { + jl_printf(s_precompile, " # nested_compile"); + } jl_printf(s_precompile, "\n"); if (s_precompile != JL_STDERR) ios_flush(&f_precompile); @@ -3457,7 +3461,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t // unspec is probably not specsig, but might be using specptr jl_atomic_store_relaxed(&codeinst->specsigflags, specsigflags & ~0b1); // clear specsig flag jl_mi_cache_insert(mi, codeinst); - record_precompile_statement(mi, 0, 0); + record_precompile_statement(mi, 0, 0, 0); return codeinst; } } @@ -3474,7 +3478,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t 0, 1, ~(size_t)0, 0, jl_nothing, NULL, NULL); jl_atomic_store_release(&codeinst->invoke, jl_fptr_interpret_call); jl_mi_cache_insert(mi, codeinst); - record_precompile_statement(mi, 0, 0); + record_precompile_statement(mi, 0, 0, 0); return codeinst; } if (compile_option == JL_OPTIONS_COMPILE_OFF) { @@ -3488,6 +3492,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t // Everything from here on is considered (user facing) compile time uint64_t compilation_start = jl_hrtime(); + int is_nested_compile = (jl_current_task->reentrant_timing & 1); uint64_t inference_start = jl_typeinf_timing_begin(); // Special-handling for reentrancy // Is a recompile if there is cached code, and it was compiled (not only inferred) before @@ -3529,7 +3534,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t codeinst = NULL; } else if (did_compile && codeinst->owner == jl_nothing) { - record_precompile_statement(mi, compile_time, is_recompile); + record_precompile_statement(mi, compile_time, is_recompile, is_nested_compile); } JL_GC_POP(); } From 66ba9d74d7ed5999d568230354348b5b6a0bccc6 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Thu, 28 Aug 2025 11:57:55 -0600 Subject: [PATCH 2/3] Rename the log to `# nested_const_compilation` --- src/gf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gf.c b/src/gf.c index 46284623044e1..d516d2cc21c0f 100644 --- a/src/gf.c +++ b/src/gf.c @@ -3254,7 +3254,7 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila } } if (is_nested) { - jl_printf(s_precompile, " # nested_compile"); + jl_printf(s_precompile, " # nested_const_compilation"); } jl_printf(s_precompile, "\n"); if (s_precompile != JL_STDERR) From 38eb50ab1d46419c8ae040a074499bfc58ec4c41 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 2 Sep 2025 16:11:19 -0600 Subject: [PATCH 3/3] Update src/gf.c Co-authored-by: Ian Butterworth --- src/gf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gf.c b/src/gf.c index d516d2cc21c0f..942fd30ddd025 100644 --- a/src/gf.c +++ b/src/gf.c @@ -3254,7 +3254,7 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila } } if (is_nested) { - jl_printf(s_precompile, " # nested_const_compilation"); + jl_printf(s_precompile, " # nested const compilation"); } jl_printf(s_precompile, "\n"); if (s_precompile != JL_STDERR)