Skip to content

Commit

Permalink
speed up dispatch on parameterized function types (#31089)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Feb 16, 2019
1 parent b9c4a85 commit dfee945
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
mt->kwsorter = NULL;
mt->backedges = NULL;
JL_MUTEX_INIT(&mt->writelock);
mt->offs = 1;
return mt;
}

Expand Down Expand Up @@ -480,6 +481,8 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype(
if (!abstract) {
tn->mt = jl_new_method_table(name, module);
jl_gc_wb(tn, tn->mt);
if (jl_svec_len(parameters) > 0)
tn->mt->offs = 0;
}
}
t->name = tn;
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ static void jl_reinit_item(jl_value_t *v, int how, arraylist_t *tracee_list)
jl_methtable_t *mt = (jl_methtable_t*)v;
jl_typemap_rehash(mt->defs, 0);
// TODO: consider reverting this when we can split on Type{...} better
jl_typemap_rehash(mt->cache, 1); //(mt == jl_type_typename->mt) ? 0 : 1);
jl_typemap_rehash(mt->cache, mt->offs);
if (tracee_list)
arraylist_push(tracee_list, mt);
break;
Expand Down
3 changes: 1 addition & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ const struct jl_typemap_info tfunc_cache = {

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

/// ----- Insertion logic for special entries ----- ///
Expand Down
13 changes: 8 additions & 5 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,13 +1736,14 @@ void jl_init_types(void) JL_GC_DISABLED
jl_methtable_type->name->mt = jl_new_method_table(jl_methtable_type->name->name, core);
jl_methtable_type->super = jl_any_type;
jl_methtable_type->parameters = jl_emptysvec;
jl_methtable_type->name->names = jl_perm_symsvec(9, "name", "defs",
jl_methtable_type->name->names = jl_perm_symsvec(10, "name", "defs",
"cache", "max_args",
"kwsorter", "module",
"backedges", "", "");
jl_methtable_type->types = jl_svec(9, jl_sym_type, jl_any_type, jl_any_type, jl_any_type/*jl_long*/,
"backedges", "", "", "offs");
jl_methtable_type->types = jl_svec(10, jl_sym_type, jl_any_type, jl_any_type, jl_any_type/*jl_long*/,
jl_any_type, jl_any_type/*module*/,
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/);
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/,
jl_any_type/*uint8*/);
jl_methtable_type->uid = jl_assign_type_uid();
jl_methtable_type->instance = NULL;
jl_methtable_type->struct_decl = NULL;
Expand Down Expand Up @@ -2212,10 +2213,12 @@ void jl_init_types(void) JL_GC_DISABLED
jl_svecset(jl_methtable_type->types, 6, jl_array_any_type);
#ifdef __LP64__
jl_svecset(jl_methtable_type->types, 7, jl_int64_type); // unsigned long
jl_svecset(jl_methtable_type->types, 8, jl_int64_type); // uint32_t plus alignment
#else
jl_svecset(jl_methtable_type->types, 7, jl_int32_type); // DWORD
#endif
jl_svecset(jl_methtable_type->types, 8, jl_int32_type); // uint32_t
#endif
jl_svecset(jl_methtable_type->types, 9, jl_uint8_type);
jl_svecset(jl_method_type->types, 11, jl_method_instance_type);
jl_svecset(jl_method_instance_type->types, 11, jl_voidpointer_type);
jl_svecset(jl_method_instance_type->types, 12, jl_voidpointer_type);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ typedef struct _jl_methtable_t {
jl_module_t *module; // used for incremental serialization to locate original binding
jl_array_t *backedges;
jl_mutex_t writelock;
uint8_t offs; // 0, or 1 to skip splitting typemap on first (function) argument
} jl_methtable_t;

typedef struct {
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,9 @@ function deserialize_typename(s::AbstractSerializer, number)
maxa = deserialize(s)::Int
if makenew
tn.mt = ccall(:jl_new_method_table, Any, (Any, Any), name, tn.module)
if !isempty(parameters)
tn.mt.offs = 0
end
tn.mt.name = mtname
tn.mt.max_args = maxa
for def in defs
Expand Down

4 comments on commit dfee945

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.