moose
moose copied to clipboard
Use less closures
We're currently always compiling kernels to closures, with some performance overhead as a result.
Letting the kernel traits return enums instead would probably not solve this, but we might be able to use as associated type.
This
pub trait NullaryKernel<S: Session, P, Y> {
fn compile(&self, plc: &P) -> Result<Box<dyn Fn(&S, &P) -> Result<Y> + Send>>;
}
would be changed to this
pub trait NullaryKernel<S: Session, P, Y>
where
Self::Compiled: Fn(&S, &P) -> Result<Y> + Send,
{
type Compiled;
fn compile(&self, plc: &P) -> Result<Self::Compiled>;
}
and the kernel!
macro could use flavour to determine if the return type should be a closure or simply a function pointer.
cc @voronaam