Roadmap for small binaries

Basically, (single) dynamic dispatch itself can be statically compiled with “virtual tables” in .NET CLR/JVM, which can be theoretically much slower than Julia’s multiple dispatch but do not suffer at all from re-compilation and runtime compilation latency.

Dylan’s handling does not really work for Julia due to its lack of support for parametric polymorphism (could be roughly regarded as “generics” tho not precise). Parametric polymorphism is fully supported in Julia.

You could ignore those horrible concepts but have a look at the following code:

f(x::Vector{T}) where T = ...
f(x::AbstractVector) = ...
f(x::Vector{Int}) = ...

The code could demonstrate why we cannot have fast runtime multiple dispatch like that in some LISP dialects. Besides, multiple dispatch without parametric types can be easily expressed by looking up dictionaries:

f(x::VectorInt32) = 1
f(x::VectorInt64) = 2

//  f(x) --> method_table[(typeof(x), )](x)
//
// things can be a bit more difficult when supporting subclassing, 
// but still damn easy when comparing to Julia's cases.

Actually, parametric polymorphism is powerful, and widely recognized and used in industrial languages (including nearly all C-family languages and static FP languages). However, parametric polymorphism can cause issues such as finding “principal types” or finding “most specific types” or finding most appropriate method – All these “finding *” must be slow at runtime and cannot be optimized without magic things like a quantum computer.

As a result, a “generic” Julia function could have infinite number of valid compiled (and optimized) specialization, and Julia code that is heavily dynamic cannot compile/optimize them in advanced. So far, Julia usually does a new compilation when finding a required specialization for a “generic” function, this promises the fast execution in the second time but produces severe “time-to-first-plot” latency in some cases.

That’s the whole story.

To solve the issues, the company I’m working for is now concentrating on generating small binaries (both standalone executables and dynamic libraries) for Julia codebase that is “reasonably static”. The project has made progress during mid-2023 and might be available for public use in the early 2024. Our work is based on code_typed in a frozen world age.

30 Likes