Conversation
…ExpressionForDangerousProps Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Optimizes expression validation performance by avoiding repeated compilation of constant regular expressions in validateExpressionForDangerousProps, which is invoked frequently during recursive expression validation.
Changes:
- Hoists the expression-splitting regexp into a package-level precompiled variable.
- Hoists the numeric-part-matching regexp into a package-level precompiled variable.
- Updates
validateExpressionForDangerousPropsto reuse the precompiled regexps.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // exprPartSplitRe splits expression strings on dot and bracket characters | ||
| exprPartSplitRe = regexp.MustCompile(`[.\[\]]+`) | ||
| // exprNumericPartRe matches purely numeric expression parts (array indices) | ||
| exprNumericPartRe = regexp.MustCompile(`^\d+$`) |
There was a problem hiding this comment.
The package-level precompiled regexp vars in this file consistently use the ...Regex suffix (e.g., expressionRegex, needsStepsRegex, numberLiteralRegex). These new names use ...Re, which is inconsistent and makes it harder to scan for regexp vars. Consider renaming to exprPartSplitRegex / exprNumericPartRegex (or another ...Regex-suffixed convention used here).
validateExpressionForDangerousPropswas compiling two constant regex patterns on every call — one at function scope and one inside theforloop — accumulating unnecessary allocations sincevalidateSingleExpressionis recursive and runs on every expression in every compiled workflow.Changes
pkg/workflow/expression_validation.go: AddedexprPartSplitReandexprNumericPartReto the existing package-levelvarblock; replaced the inlineregexp.MustCompilecalls with references to these vars.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.