From 3be44f24aaa7db4cffa49caaed50d82b69f0c89d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 05:12:52 +0000 Subject: [PATCH 1/3] Initial plan From a77f838de23ea923363259f24bdd14bfe28c2d90 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 05:16:47 +0000 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20replace=20O(n=C2=B2)=20string=20con?= =?UTF-8?q?cat=20with=20strings.Builder=20in=20expression=5Fparser.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `current += string(char)` and `current += ...` accumulations with `strings.Builder` in both `BreakLongExpression` and `BreakAtParentheses`. - BreakLongExpression: single `var current strings.Builder`; also eliminates the inner `sb strings.Builder` that was used for quoted strings (now writes directly into `current`) - BreakAtParentheses: same pattern; use `current.Len()` instead of `len(current)` for the length check Fixes the O(n²) allocation pattern identified in the audit." Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b3b6cf6b-6f89-413d-9e51-ebabb6483911 --- pkg/workflow/expression_parser.go | 40 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/pkg/workflow/expression_parser.go b/pkg/workflow/expression_parser.go index 36c5739fc80..cfcdd1ec94f 100644 --- a/pkg/workflow/expression_parser.go +++ b/pkg/workflow/expression_parser.go @@ -329,7 +329,7 @@ func BreakLongExpression(expression string) []string { expressionsLog.Printf("Breaking long expression: length=%d", len(expression)) var lines []string - current := "" + var current strings.Builder i := 0 for i < len(expression) { @@ -339,13 +339,12 @@ func BreakLongExpression(expression string) []string { // Support single quotes ('), double quotes ("), and backticks (`) if char == '\'' || char == '"' || char == '`' { quote := char - current += string(char) + current.WriteByte(char) i++ // Continue until closing quote - var sb strings.Builder for i < len(expression) { - sb.WriteByte(expression[i]) + current.WriteByte(expression[i]) if expression[i] == quote { i++ break @@ -353,12 +352,11 @@ func BreakLongExpression(expression string) []string { if expression[i] == '\\' && i+1 < len(expression) { i++ // Skip escaped character if i < len(expression) { - sb.WriteByte(expression[i]) + current.WriteByte(expression[i]) } } i++ } - current += sb.String() continue } @@ -366,13 +364,13 @@ func BreakLongExpression(expression string) []string { if i+2 <= len(expression) { next2 := expression[i : i+2] if next2 == "||" || next2 == "&&" { - current += next2 + current.WriteString(next2) i += 2 // If the current line is getting long (>ExpressionBreakThreshold chars), break here - if len(strings.TrimSpace(current)) > int(constants.ExpressionBreakThreshold) { - lines = append(lines, strings.TrimSpace(current)) - current = "" + if len(strings.TrimSpace(current.String())) > int(constants.ExpressionBreakThreshold) { + lines = append(lines, strings.TrimSpace(current.String())) + current.Reset() // Skip whitespace after operator for i < len(expression) && (expression[i] == ' ' || expression[i] == '\t') { i++ @@ -383,13 +381,13 @@ func BreakLongExpression(expression string) []string { } } - current += string(char) + current.WriteByte(char) i++ } // Add the remaining part - if strings.TrimSpace(current) != "" { - lines = append(lines, strings.TrimSpace(current)) + if strings.TrimSpace(current.String()) != "" { + lines = append(lines, strings.TrimSpace(current.String())) } // If we still have very long lines, try to break at parentheses @@ -413,12 +411,12 @@ func BreakAtParentheses(expression string) []string { } var lines []string - current := "" + var current strings.Builder parenDepth := 0 for i := 0; i < len(expression); i++ { char := expression[i] - current += string(char) + current.WriteByte(char) switch char { case '(': @@ -427,7 +425,7 @@ func BreakAtParentheses(expression string) []string { parenDepth-- // If we're back to zero depth and the line is getting long, consider a break - if parenDepth == 0 && len(current) > 80 && i < len(expression)-1 { + if parenDepth == 0 && current.Len() > 80 && i < len(expression)-1 { // Look ahead to see if there's a logical operator j := i + 1 for j < len(expression) && (expression[j] == ' ' || expression[j] == '\t') { @@ -436,9 +434,9 @@ func BreakAtParentheses(expression string) []string { if j+1 < len(expression) && (expression[j:j+2] == "||" || expression[j:j+2] == "&&") { // Add the operator to current line and break - current += expression[i+1 : j+2] - lines = append(lines, strings.TrimSpace(current)) - current = "" + current.WriteString(expression[i+1 : j+2]) + lines = append(lines, strings.TrimSpace(current.String())) + current.Reset() i = j + 2 - 1 // Set to j+2-1 so the loop increment makes i = j+2 // Skip whitespace after operator @@ -451,8 +449,8 @@ func BreakAtParentheses(expression string) []string { } // Add remaining part - if strings.TrimSpace(current) != "" { - lines = append(lines, strings.TrimSpace(current)) + if strings.TrimSpace(current.String()) != "" { + lines = append(lines, strings.TrimSpace(current.String())) } return lines From 487b77a786f972e7d93f1852c0d9c4e6b3ab67ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Mar 2026 05:18:14 +0000 Subject: [PATCH 3/3] perf: avoid double TrimSpace calls by storing trimmed result in local variable Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b3b6cf6b-6f89-413d-9e51-ebabb6483911 --- pkg/workflow/expression_parser.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/workflow/expression_parser.go b/pkg/workflow/expression_parser.go index cfcdd1ec94f..5019c85f1b6 100644 --- a/pkg/workflow/expression_parser.go +++ b/pkg/workflow/expression_parser.go @@ -368,8 +368,8 @@ func BreakLongExpression(expression string) []string { i += 2 // If the current line is getting long (>ExpressionBreakThreshold chars), break here - if len(strings.TrimSpace(current.String())) > int(constants.ExpressionBreakThreshold) { - lines = append(lines, strings.TrimSpace(current.String())) + if trimmed := strings.TrimSpace(current.String()); len(trimmed) > int(constants.ExpressionBreakThreshold) { + lines = append(lines, trimmed) current.Reset() // Skip whitespace after operator for i < len(expression) && (expression[i] == ' ' || expression[i] == '\t') { @@ -386,8 +386,8 @@ func BreakLongExpression(expression string) []string { } // Add the remaining part - if strings.TrimSpace(current.String()) != "" { - lines = append(lines, strings.TrimSpace(current.String())) + if trimmed := strings.TrimSpace(current.String()); trimmed != "" { + lines = append(lines, trimmed) } // If we still have very long lines, try to break at parentheses @@ -449,8 +449,8 @@ func BreakAtParentheses(expression string) []string { } // Add remaining part - if strings.TrimSpace(current.String()) != "" { - lines = append(lines, strings.TrimSpace(current.String())) + if trimmed := strings.TrimSpace(current.String()); trimmed != "" { + lines = append(lines, trimmed) } return lines