Skip to content

Commit 72735ee

Browse files
committed
gf.c: make edge de-duplication a caller responsibility
On my system, this saves ~500 ms when loading CairoMakie (and all dependent packages)
1 parent 858263a commit 72735ee

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/gf.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,9 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee,
19971997
jl_gc_wb(callee, backedges);
19981998
}
19991999
else {
2000+
#ifndef JL_NDEBUG
2001+
// It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only
2002+
// checking its work.
20002003
size_t i = 0, l = jl_array_nrows(backedges);
20012004
for (i = 0; i < l; i++) {
20022005
// optimized version of while (i < l) i = get_next_edge(callee->backedges, i, &invokeTypes, &mi);
@@ -2012,6 +2015,8 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee,
20122015
break;
20132016
}
20142017
}
2018+
assert(!found && "duplicate back-edge registered");
2019+
#endif
20152020
}
20162021
if (!found)
20172022
push_edge(backedges, invokesig, caller);
@@ -2037,14 +2042,20 @@ JL_DLLEXPORT void jl_method_table_add_backedge(jl_methtable_t *mt, jl_value_t *t
20372042
else {
20382043
// check if the edge is already present and avoid adding a duplicate
20392044
size_t i, l = jl_array_nrows(mt->backedges);
2045+
#ifndef JL_NDEBUG
2046+
// It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only
2047+
// checking its work.
2048+
int found = 0;
20402049
for (i = 1; i < l; i += 2) {
20412050
if (jl_array_ptr_ref(mt->backedges, i) == (jl_value_t*)caller) {
20422051
if (jl_types_equal(jl_array_ptr_ref(mt->backedges, i - 1), typ)) {
2043-
JL_UNLOCK(&mt->writelock);
2044-
return;
2052+
found = 1;
2053+
break;
20452054
}
20462055
}
20472056
}
2057+
assert(!found && "duplicate back-edge registered");
2058+
#endif
20482059
// reuse an already cached instance of this type, if possible
20492060
// TODO: use jl_cache_type_(tt) like cache_method does, instead of this linear scan?
20502061
for (i = 1; i < l; i += 2) {

0 commit comments

Comments
 (0)