moose icon indicating copy to clipboard operation
moose copied to clipboard

Use less closures

Open mortendahl opened this issue 3 years ago • 1 comments

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.

mortendahl avatar Nov 22 '21 11:11 mortendahl

cc @voronaam

mortendahl avatar Nov 22 '21 11:11 mortendahl