Skip to content

Units interface package #595

Open
Open
@tfiers

Description

@tfiers

using Unitful currently takes 1 to 3 seconds1.

This is fine if you're planning on actually using physical units in your Julia session.2
But it adds to the load time of downstream packages that offer optional Unitful support.

My concrete motivation for writing this issue is that I want to add Unitful support to Distributions.jl:

Doing that would require adding Unitful as a dependency to Distributions. But most Distributions.jl users will not use the new unitful distributions; and they would still get the added start-up latency.

That is why I propose to create a very lightweight package that defines just the interface/API for working with units in Julia. Something like UnitfulCore, or UnitsInterface.jl.

Downstream packages offering physical unit support would then load just that interface package.
(If the user wants to actually use the unit support, they have to explicitly be using Unitful, DownstreamPkg).

This pattern has been applied before, e.g. in StaticArrays.jl. From its readme:

Most of the primary array types exported by StaticArrays.jl are defined in the small interface package StaticArraysCore.jl. This includes e.g., the definitions of the abstract type StaticArray and the concrete types SArray, MArray, and SizedArray (as well as their dimension-specific aliases). This enables downstream packages to implement new methods for these types without depending on (and hence loading) the entirety of StaticArrays.jl, and thereby to avoid incurring the full load-time of StaticArrays.jl (which is on the order of 0.6 s for StaticArrays.jl v1.4 on Julia v1.7).


So my question to the maintainers of Unitful.jl is: would you be open to adding such an interface package as a dependency of Unitful, and moving some core types and functions to that package (or having them subtype from the package) ?



Footnotes

  1. @time using Unitful gives 1.0 seconds on replit, and between 1.6 and 2.6 seconds on my laptop (Julia 1.8).

  2. Though a @precompile_all_calls block might be a good idea to add to src/ in any case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions