Package extensions

07/26/2023, 7:00 PM7:30 PM UTC
26-100

Abstract:

Package extensions are a new feature for packages available in Julia 1.9. It aims to solve the problem where you might be reluctant to take on a package as a dependency just to extend a function to a type in that package due to e.g. increased load time of the package.

Description:

The multiple dispatch paradigm of Julia makes it very easy to extend functionality to new types. A package can just define a new method of a generic function that accepts a type in another package, and anyone that calls that function with that type will get the extended behavior. An example of this could be a plotting package that extends a plotting method to various types in the Julia ecosystem.

However, to extend a method with a type from another package, one needs to make that package a dependency. This has a cost, most noticeably in package load time. This means that for a package author, there is always a conflict between wanting to provide useful method extensions and keeping the load time of the package small.

The go-to solution for the problem above has been the Requires.jl package. In Requires.jl one defines a piece of code that gets automatically executed when another package is loaded. This code typically adds some extra method for one of the types in the package. Since you are not directly depending on the package, you no longer unconditionally pay the loading cost of it.

Unfortunately, Requires.jl comes with some drawbacks:

  • The code that gets executed when a package gets loaded is eval-ed into the module which means that that code can not be precompiled, leading to worse latency.
  • It is not possible to set any compatibility constraints on the packages triggering the
  • Requires.jl had issues with PackageCompiler since it needed access to files during runtime.

The new "package extension" functionality in 1.9 is meant to fully replace the usage of Requires.jl while solving the issues mentioned above. This talk will give an overview of how the new extension system works, discuss best practices and give some examples of its usage from the package ecosystem.

Platinum sponsors

JuliaHub

Gold sponsors

ASML

Silver sponsors

Pumas AIQuEra Computing Inc.Relational AIJeffrey Sarnoff

Bronze sponsors

Jolin.ioBeacon BiosignalsMIT CSAILBoeing

Academic partners

NAWA

Local partners

Postmates

Fiscal Sponsor

NumFOCUS