-
Notifications
You must be signed in to change notification settings - Fork 458
perf: fix CompileMemoryUsage regression by optimizing normalizeBlankLines and findRunValue #44995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bfdbc80
0ed762e
574b89c
19430e9
59dbe90
4db4e87
635348c
faa8824
b6f01ee
be2ad55
7e49b7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,14 @@ func mayContainInlineExpression(s string) bool { | |
| } | ||
|
|
||
| func findRunValue(keyPart string) (string, bool) { | ||
| // Fast pre-check: every regex alternative embeds "run:" (unquoted), | ||
| // "run\":" (double-quoted close), or "run':" (single-quoted close), so | ||
| // skip the regex entirely when none of those substrings is present. | ||
| if !strings.Contains(keyPart, "run:") && | ||
| !strings.Contains(keyPart, `run":`) && | ||
| !strings.Contains(keyPart, "run':") { | ||
| return "", false | ||
| } | ||
| loc := runKeyPattern.FindStringIndex(keyPart) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnosing-bugs] The pre-check 💡 Suggested testfunc TestFindRunValueFastPath(t *testing.T) {
cases := []struct {
input string
wantOk bool
}{
{`run: echo hello`, true},
{`"run": echo hello`, true},
{`{run: echo hello}`, true},
{`step: build`, false},
{`runner: ubuntu`, false}, // "run" present but not "run:"
}
for _, c := range cases {
_, ok := findRunValue(c.input)
if ok != c.wantOk {
t.Errorf("findRunValue(%q) ok=%v, want %v", c.input, ok, c.wantOk)
}
}
}@copilot please address this. |
||
| if loc == nil { | ||
| return "", false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnosing-bugs] No regression tests for the rewritten
normalizeBlankLines— a non-trivial rewrite with subtle edge-case handling (empty input, all-whitespace, no trailing newline) is exactly where a unit test suite pays off.💡 Suggested test cases
Without tests, a future refactor or Go version change could silently break the behaviour that was carefully preserved in the comments.
@copilot please address this.