Skip to content

Commit be59100

Browse files
authored
Fixup measurement for --trace-compile-timing w/ nested compilations. (#59363)
Use a separate inference_start and compilation_start, where compilation_start does not do anything special for reentrancy. Here is an example which has a quick-to-compile nested dynamic dispatch, but that nested function runs for a long time: ```julia ./julia --startup=no --trace-compile=stderr --trace-compile-timing -e ' Base.@assume_effects :foldable function nested1(x) sum(collect(x for _ in 1:1000_000_000)) end f1(x) = nested1(sizeof(x)) + x f1(2)' #= 12.7 ms =# precompile(Tuple{typeof(Main.nested1), Int64}) #= 3809.3 ms =# precompile(Tuple{typeof(Main.f1), Int64}) ``` This fixes a small issue introduced here: https://github.com/JuliaLang/julia/pull/59220/files#r2292021838
1 parent d28a587 commit be59100

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/gf.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,7 +3487,8 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
34873487
// Ok, compilation is enabled. We'll need to try to compile something (probably).
34883488

34893489
// Everything from here on is considered (user facing) compile time
3490-
uint64_t start = jl_typeinf_timing_begin();
3490+
uint64_t compilation_start = jl_hrtime();
3491+
uint64_t inference_start = jl_typeinf_timing_begin(); // Special-handling for reentrancy
34913492

34923493
// Is a recompile if there is cached code, and it was compiled (not only inferred) before
34933494
int is_recompile = 0;
@@ -3514,14 +3515,14 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35143515

35153516
if (codeinst) {
35163517
if (jl_is_compiled_codeinst(codeinst)) {
3517-
jl_typeinf_timing_end(start, is_recompile);
3518+
jl_typeinf_timing_end(inference_start, is_recompile);
35183519
// Already compiled - e.g. constabi, or compiled by a different thread while we were waiting.
35193520
return codeinst;
35203521
}
35213522

35223523
JL_GC_PUSH1(&codeinst);
35233524
int did_compile = jl_compile_codeinst(codeinst);
3524-
double compile_time = jl_hrtime() - start;
3525+
double compile_time = jl_hrtime() - compilation_start;
35253526

35263527
if (jl_atomic_load_relaxed(&codeinst->invoke) == NULL) {
35273528
// Something went wrong. Bail to the fallback path.
@@ -3551,7 +3552,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35513552
if (ucache_invoke != jl_fptr_sparam &&
35523553
ucache_invoke != jl_fptr_interpret_call) {
35533554
// only these care about the exact specTypes, otherwise we can use it directly
3554-
jl_typeinf_timing_end(start, is_recompile);
3555+
jl_typeinf_timing_end(inference_start, is_recompile);
35553556
return ucache;
35563557
}
35573558
uint8_t specsigflags;
@@ -3569,7 +3570,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35693570
jl_mi_cache_insert(mi, codeinst);
35703571
}
35713572
jl_atomic_store_relaxed(&codeinst->precompile, 1);
3572-
jl_typeinf_timing_end(start, is_recompile);
3573+
jl_typeinf_timing_end(inference_start, is_recompile);
35733574
return codeinst;
35743575
}
35753576

0 commit comments

Comments
 (0)