edouarda/brigand

universal lambda fast track

odinthenerd opened this issue · 7 comments

In order to push the speed of lambdas further we could use fast tracks for common cases, for example a transform with one input list is probably going to take an eager lambda with one input, this probably should be fast tracked. This can be done by just adding another implementation of transform (its just one line).

These kind of fast tracks are not as easy with other algorithms as the lambda is propagated into many nested meta function calls inside the implementation. Sort for example is quite complex inside yet essentially always going to be called with a binary function. In order to be able to fast track yet still have only one algorithm it seems like a good idea to make a kind of universal fast track. Essentially pass a bind<F,...> into every detail::algorithm_impl and make the F in bind<F,...> resolve to typename detail::apply<UserLambda,...>::type if F is not of the right pattern.
This means we are essentially only one wrapping of F and one extra instantiation slower than a Dimov style algorithm because we only need to pattern match once in order to fish out the trivial lambdas and need only call apply if the lambdas are not trivial.

Perhaps we could have a pre-processor macro to make writing these fast track easier or less error prone, or do you think it's a bad idea? @jfalcou ?

It may just be me being pedantic but I hate the preprocessor.

Everyone does. :-)

#196 shows how I would suggest doing this. should be just as fast as meta on metabench but it can short circuit so its way faster if your not looking for the last element (metabench is a bit bias).

newest metabench shows this concept is #winning. We should add count_if and merge #197 in order to be winning in all catagories

most algorithms have been fast tracked

There is only one place and this place is #1 :-)