Skip to content

Commit 2ad6627

Browse files
NHDalyKristofferC
authored andcommitted
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 (cherry picked from commit be59100)
1 parent 63f7c79 commit 2ad6627

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
@@ -3483,7 +3483,8 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
34833483
// Ok, compilation is enabled. We'll need to try to compile something (probably).
34843484

34853485
// Everything from here on is considered (user facing) compile time
3486-
uint64_t start = jl_typeinf_timing_begin();
3486+
uint64_t compilation_start = jl_hrtime();
3487+
uint64_t inference_start = jl_typeinf_timing_begin(); // Special-handling for reentrancy
34873488

34883489
// Is a recompile if there is cached code, and it was compiled (not only inferred) before
34893490
int is_recompile = 0;
@@ -3510,14 +3511,14 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35103511

35113512
if (codeinst) {
35123513
if (jl_is_compiled_codeinst(codeinst)) {
3513-
jl_typeinf_timing_end(start, is_recompile);
3514+
jl_typeinf_timing_end(inference_start, is_recompile);
35143515
// Already compiled - e.g. constabi, or compiled by a different thread while we were waiting.
35153516
return codeinst;
35163517
}
35173518

35183519
JL_GC_PUSH1(&codeinst);
35193520
int did_compile = jl_compile_codeinst(codeinst);
3520-
double compile_time = jl_hrtime() - start;
3521+
double compile_time = jl_hrtime() - compilation_start;
35213522

35223523
if (jl_atomic_load_relaxed(&codeinst->invoke) == NULL) {
35233524
// Something went wrong. Bail to the fallback path.
@@ -3547,7 +3548,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35473548
if (ucache_invoke != jl_fptr_sparam &&
35483549
ucache_invoke != jl_fptr_interpret_call) {
35493550
// only these care about the exact specTypes, otherwise we can use it directly
3550-
jl_typeinf_timing_end(start, is_recompile);
3551+
jl_typeinf_timing_end(inference_start, is_recompile);
35513552
return ucache;
35523553
}
35533554
uint8_t specsigflags;
@@ -3565,7 +3566,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
35653566
jl_mi_cache_insert(mi, codeinst);
35663567
}
35673568
jl_atomic_store_relaxed(&codeinst->precompile, 1);
3568-
jl_typeinf_timing_end(start, is_recompile);
3569+
jl_typeinf_timing_end(inference_start, is_recompile);
35693570
return codeinst;
35703571
}
35713572

0 commit comments

Comments
 (0)