Rewrite the internal QL pipeline
Summary: This one is still deeply hypothetical, and huge, but the potential performance gains are sufficiently huge as to be worth really digging down and dealing with it.
In airy theory, the plan looks like this:
InternalMethod
gains a new method, with a signature that is something like:
def lazyQLApply(inv: Invocation): Stream[Something, NewInvocationValue]
where Stream
is probably the fs2 version of that, NewInvocationValue
is now simply Either[QuerkiError, QValue]
, and I'm not entirely clear on what Something
is.
- This gets evaluated over
IO[Task]
, which is what gives us our asynchrony, but I don't believe the functions usually needs to know that. That said, we need to understand from the very beginning how we inject the desired Async Monad into this, so it's quite possible that we need a context bound of : Async[F]
involved here.
- The default implementation of
lazyQLApply()
just does a dumb, inefficient delegation to the existing _qlApply()
function, so we have an upgrade path.
- The engine should now call
lazyQLApply()
instead of _qlApply()
, and we need to get that working.
- Now we begin to go through, reimplementing
_qlApply
as _lazyQLApply
, and dropping the old versions. This will almost certainly require major enhancements to Invocation
, to replace the functions with ones that make sense in the new world, but that's fine. See if there are sensible ways to rewrite Invocation at this point, possibly breaking it down into a bunch of typeclasses, to make it less of a gigantic mess.
- Profit!
Start by doing some experiments, outside Querki proper, with mocked-up, simplified versions of the existing signatures, and figure out the details there. Make sure that the experiments include straightforwardly lazy operations (which I think are the majority), strict ones (to emulate _sort()
and the few other functions that require strictness), and Future-based ones (for the few functions that delegate to the outside world). Once we have a sufficient base of decent experiments, I'll be more inclined to believe that I know what I'm doing here.