Interestingly Stable Methods - prl-julia/julia-type-stability GitHub Wiki

For every package several most polymorphic methods -- in terms of number of return types across all observed calls. This number is given in parenthesis after a method name.

To go:

  • Knet (v1.4.5)
  • Plots (v1.10.6)
  • Pluto (v0.12.21)
  • Gadfly (v1.3.1)

JuMP (v0.21.6)

A greatly polymorphic package (also large): first five stable methods had 19+ return types.

  • MathOptInterface.get (41+21): a container-operating extraction function, parametric in the type of contained elements.

  • MathOptInterface.map_indices (29): a form of identity function.

  • build_constraint (21+14): create a polymorphic wrapper.

  • MutableArithmetics.add_mul (19+14): generic arithmetic for library-defined types.

  • _functionize (16): the identity function.

  • MutableArithmetics.sub_mul (13): same as add_mul above.

  • _add_or_set! (13): a container-operating updating function, parametric in the type of contained elements.

  • promote_operation (13): type-level computation; in particular, the function returns the type of result of a given operation when applied to arguments of given types, and the method computes the output type of * when applied to to T (type parameter) (this is, unsurprisingly, T).

IJulia (v1.23.2)

One method with 10 return types and all others have only one return types.

  • display_mimestring (10): a form of identity function.

Genie (v1.16.0)

No methods with more that 2 return types.

  • secret_token! (2): a form of identity function.

  • gvector_to_jl (2): a conversion/restructuring utility, parametric in the type of contained elements.

Gen (v0.4.2)

  1. get_values_shallow + get_submaps_shallow (7+5): reshaping a container. Parametric.

  2. typecheck_arg (6): the identity function (typechecking a "simple" value that has the same type in Julia as in their DSL).

  3. compile_dist_with_args (5): turns one polymorphic struct into another with non-trivial amount of computations (!).

  4. get_submaps_shallow (5): restructuring a data structure into a tuple (hence genericity).

  5. get_return_type (5): type-level stuff (returns a type of a polymorphic input).

Flux (v0.11.6)

Consider two most-polymorphic methods, as others have 4 or less return types.

  1. extraChain (7 return types): it's a map ($ x) over a tuple, so a parametric method.

  2. DataLoader constructor (6 ret types): a parametric wrapper.

DifferentialEquations (v6.16.0)

  1. dimension (56 + 29 r.t.): extracts type info (dimension(u::Units{U,D}) where {U,D} = D).

  2. unpack(_args) (12+12): parametrically reshaping arguments.

  3. convert from the Static package (9): convert term-holding type into the corresponding term (e.g. turn Type{StaticInt{42}} into StaticInt{42}).

  4. solution_new_retcode (8+8): smart constructor.

  5. convert: overloiading base functions to SIMDed datatypes. Parametric.

JSON.jl (v0.21.1)

Only 11.5% of stable methods (total 8) are interesting (supports conjecture 1) and the most polymorphic ones return only 3 different types. Going over those interesting stable methods in the order of decreasing number of return types:

  1. lower (src/Writer.jl:43): is an identity function modulo wrapping the result into a polymorphic record.

  2. show_json (src/Writer.jl:43): a printing procedurs with some control-flow inside that makes it finish with different calls; 99% of time it returns either Nothing or Union{} which are morally equivalent. Once it returns Bool which is weird.