precompile 0.1.0

Monomorphization precompilation library
Documentation
  • Coverage
  • 0%
    0 out of 1 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 487.66 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sarah-quinones/precompile
    19 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sarah-quinones

precompile

precompile is a nightly-only crate that uses #![feature(specialization)] for precompiling specific monomorphizations of a generic function. This can provide a benefit for generic functions that are expected to be used with a limited set of types from multiple downstream crates.

For example:

// crate: A
pub fn generic_fn<T>() {
    // ...
}

// crate B
A::generic_fn::<u32>();

// crate C
A::generic_fn::<u32>();

This code will usually compile A::generic_fn::<u32> twice.

Whereas if we precompile generic_fn:

// crate: A
#[precompile::precompile]
#[precompile_with(u32)]
pub fn generic_fn<T>() {
    // ...
}

Then no matter how many crates use A::generic_fn::<u32>, it will only be compiled once, when the crate A is built.

This means a possibly larger upfront compile-time cost for building A, in exchange for a cheaper monomorphization cost when used downstream.