-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
QE 2021-12-13, QE 2021-12-27, QE 2022-01-10, QE 2022-01-24
One idea to improve the performance of a $sort + $first/$firstN pipeline is to skip evaluating the Accumulator 'argument' expression for $first/$firstN if a given AccumulatorState doesn't need any more input (i.e. when we have 1 or 'n' values, respectively). This could potentially save time if it's expensive to evaluate the argument expression. (note that we can never short circuit $group entirely: as long as we have input documents, there's a chance that we can start a new group).
This task should see whether this produces any performance benefits for $first/firstN groups (that is, we need to figure out first whether this yields performance improvements; because you still have to inspect every document that comes into group no matter what, it might be the case that skipping expression evaluation doesn't save so much time).