Skip to content

Commit dfee945

Browse files
authored
speed up dispatch on parameterized function types (#31089)
1 parent b9c4a85 commit dfee945

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

src/datatype.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
4747
mt->kwsorter = NULL;
4848
mt->backedges = NULL;
4949
JL_MUTEX_INIT(&mt->writelock);
50+
mt->offs = 1;
5051
return mt;
5152
}
5253

@@ -480,6 +481,8 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype(
480481
if (!abstract) {
481482
tn->mt = jl_new_method_table(name, module);
482483
jl_gc_wb(tn, tn->mt);
484+
if (jl_svec_len(parameters) > 0)
485+
tn->mt->offs = 0;
483486
}
484487
}
485488
t->name = tn;

src/dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ static void jl_reinit_item(jl_value_t *v, int how, arraylist_t *tracee_list)
23752375
jl_methtable_t *mt = (jl_methtable_t*)v;
23762376
jl_typemap_rehash(mt->defs, 0);
23772377
// TODO: consider reverting this when we can split on Type{...} better
2378-
jl_typemap_rehash(mt->cache, 1); //(mt == jl_type_typename->mt) ? 0 : 1);
2378+
jl_typemap_rehash(mt->cache, mt->offs);
23792379
if (tracee_list)
23802380
arraylist_push(tracee_list, mt);
23812381
break;

src/gf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ const struct jl_typemap_info tfunc_cache = {
117117

118118
static int8_t jl_cachearg_offset(jl_methtable_t *mt)
119119
{
120-
// TODO: consider reverting this when we can split on Type{...} better
121-
return 1; //(mt == jl_type_type_mt) ? 0 : 1;
120+
return mt->offs;
122121
}
123122

124123
/// ----- Insertion logic for special entries ----- ///

src/jltypes.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,13 +1736,14 @@ void jl_init_types(void) JL_GC_DISABLED
17361736
jl_methtable_type->name->mt = jl_new_method_table(jl_methtable_type->name->name, core);
17371737
jl_methtable_type->super = jl_any_type;
17381738
jl_methtable_type->parameters = jl_emptysvec;
1739-
jl_methtable_type->name->names = jl_perm_symsvec(9, "name", "defs",
1739+
jl_methtable_type->name->names = jl_perm_symsvec(10, "name", "defs",
17401740
"cache", "max_args",
17411741
"kwsorter", "module",
1742-
"backedges", "", "");
1743-
jl_methtable_type->types = jl_svec(9, jl_sym_type, jl_any_type, jl_any_type, jl_any_type/*jl_long*/,
1742+
"backedges", "", "", "offs");
1743+
jl_methtable_type->types = jl_svec(10, jl_sym_type, jl_any_type, jl_any_type, jl_any_type/*jl_long*/,
17441744
jl_any_type, jl_any_type/*module*/,
1745-
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/);
1745+
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/,
1746+
jl_any_type/*uint8*/);
17461747
jl_methtable_type->uid = jl_assign_type_uid();
17471748
jl_methtable_type->instance = NULL;
17481749
jl_methtable_type->struct_decl = NULL;
@@ -2212,10 +2213,12 @@ void jl_init_types(void) JL_GC_DISABLED
22122213
jl_svecset(jl_methtable_type->types, 6, jl_array_any_type);
22132214
#ifdef __LP64__
22142215
jl_svecset(jl_methtable_type->types, 7, jl_int64_type); // unsigned long
2216+
jl_svecset(jl_methtable_type->types, 8, jl_int64_type); // uint32_t plus alignment
22152217
#else
22162218
jl_svecset(jl_methtable_type->types, 7, jl_int32_type); // DWORD
2217-
#endif
22182219
jl_svecset(jl_methtable_type->types, 8, jl_int32_type); // uint32_t
2220+
#endif
2221+
jl_svecset(jl_methtable_type->types, 9, jl_uint8_type);
22192222
jl_svecset(jl_method_type->types, 11, jl_method_instance_type);
22202223
jl_svecset(jl_method_instance_type->types, 11, jl_voidpointer_type);
22212224
jl_svecset(jl_method_instance_type->types, 12, jl_voidpointer_type);

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ typedef struct _jl_methtable_t {
515515
jl_module_t *module; // used for incremental serialization to locate original binding
516516
jl_array_t *backedges;
517517
jl_mutex_t writelock;
518+
uint8_t offs; // 0, or 1 to skip splitting typemap on first (function) argument
518519
} jl_methtable_t;
519520

520521
typedef struct {

stdlib/Serialization/src/Serialization.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,9 @@ function deserialize_typename(s::AbstractSerializer, number)
10851085
maxa = deserialize(s)::Int
10861086
if makenew
10871087
tn.mt = ccall(:jl_new_method_table, Any, (Any, Any), name, tn.module)
1088+
if !isempty(parameters)
1089+
tn.mt.offs = 0
1090+
end
10881091
tn.mt.name = mtname
10891092
tn.mt.max_args = maxa
10901093
for def in defs

0 commit comments

Comments
 (0)