Skip to content

sarah-quinones/precompile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages