Skip to content

Commit

Permalink
eval: precompute expression string (Netflix#1707)
Browse files Browse the repository at this point in the history
for large group by expressions it can be expensive to
recompute the expression string for every output message.
Precompute for all messages from a given expression.
  • Loading branch information
brharrington authored Oct 15, 2024
1 parent 0dea833 commit 946926a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ object TimeSeriesMessage {
* Time series to use for the message.
* @param palette
* If defined then include presentation metadata.
* @param exprStr
* String view of the expression. Should match `expr`, but may be precomputed for
* group by expressions with many messages.
*/
def apply(
expr: StyleExpr,
context: EvalContext,
ts: TimeSeries,
palette: Option[String] = None
palette: Option[String] = None,
exprStr: Option[String] = None
): TimeSeriesMessage = {
val query = expr.toString
val query = exprStr.getOrElse(expr.toString)
val offset = Strings.toString(Duration.ofMillis(expr.offset))
val outputTags = ts.tags + (TagKey.offset -> offset)
val id = TaggedItem.computeId(outputTags + ("atlas.query" -> query)).toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private[stream] class FinalExprEval(exprInterpreter: ExprInterpreter)
// Generate the time series and diagnostic output
val output = recipients.flatMap {
case (styleExpr, infos) =>
val exprStr = styleExpr.toString
val ids = infos.map(_.id)
// Use an identity map for the state to ensure that multiple equivalent stateful
// expressions, e.g. derivative(a) + derivative(a), will have isolated state.
Expand All @@ -221,7 +222,8 @@ private[stream] class FinalExprEval(exprInterpreter: ExprInterpreter)
styleExpr,
context,
t.withLabel(styleExpr.legend(t)),
info.palette
info.palette,
Some(exprStr)
)
new MessageEnvelope(info.id, ts)
}
Expand Down

0 comments on commit 946926a

Please sign in to comment.