Skip to content

perf: fix CompileMemoryUsage regression — switch compiled-YAML parsing to yaml.v3#44353

Closed
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/performance-fix-compile-memory-usage
Closed

perf: fix CompileMemoryUsage regression — switch compiled-YAML parsing to yaml.v3#44353
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/performance-fix-compile-memory-usage

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

BenchmarkCompileMemoryUsage regressed 124% (~9,441 → ~94,323 allocs/op) due to goccy/go-yaml allocating ~82,631 objects parsing a 100KB compiled workflow YAML. gopkg.in/yaml.v3 does the same parse in ~15,607 allocs (5×fewer), and is already a dependency.

Changes

  • compiler.go, schema_validation.go — switch all yaml.Unmarshal call sites from goccy/go-yaml to gopkg.in/yaml.v3. Both libraries return map[string]any for YAML mappings, making this a drop-in replacement.

  • template_injection_validation.go — extend allowedRunScriptExpressionRegex to include toJSON(...) patterns. The compiler emits ${{ toJSON(steps.determine-automatic-lockdown.outputs.visibility) }} inside heredoc run blocks; without this, the text scanner sets hasDisallowed=true and triggers a redundant yaml.Unmarshal on the skip-validation path.

Result

Metric Before After Baseline
allocs/op 94,323 ~9,421 9,441
ns/op 17.4ms ~4.9ms 7.78ms

Switch compiled-YAML parsing from goccy/go-yaml to gopkg.in/yaml.v3 in
compiler.go and schema_validation.go. The goccy library allocates ~82,631
objects parsing a 100KB compiled YAML; yaml.v3 only allocates ~15,607 (5x
fewer). Both libraries return map[string]any for YAML mappings, making
yaml.v3 a drop-in replacement for this path.

Also extend allowedRunScriptExpressionRegex to include toJSON(...) patterns,
preventing false-positive hasDisallowed flags for compiler-generated
toJSON() wrapper expressions in run blocks (e.g. sink-visibility runtime
expressions in mcp_renderer_guard.go), which would otherwise trigger an
unnecessary yaml.Unmarshal in the text-scan path.

Result: BenchmarkCompileMemoryUsage goes from 94,323 allocs/op back to
~9,421 allocs/op, matching the historical baseline of 9,441 allocs/op.
Timing improves from 17.4ms to ~4.9ms (better than the 7.78ms baseline).

Fixes #44345

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix performance regression in CompileMemoryUsage perf: fix CompileMemoryUsage regression — switch compiled-YAML parsing to yaml.v3 Jul 8, 2026
Copilot AI requested a review from pelikhan July 8, 2026 17:10
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category chore/perf
Risk 🟡 medium
Score 44/100 (impact:22 urgency:12 quality:10)
Action ⏸ defer

Status: DRAFT — needs undraft + CI before review.

Fixes 124% alloc regression in BenchmarkCompileMemoryUsage by switching goccy/go-yamlgopkg.in/yaml.v3. Small targeted change (23+/13-, 3 files). yaml.v3 already a dependency.

Run §28966928999

Generated by 🔧 PR Triage Agent · 106.9 AIC · ⌖ 10.9 AIC · ⊞ 5.4K ·

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category chore / perf
Risk 🟡 Medium
Priority Score 42 / 100
Action defer

Score breakdown: Impact 18 + Urgency 14 + Quality 10

Rationale: DRAFT. Fixes CompileMemoryUsage regression by switching to yaml.v3 parsing. Performance improvement, not critical path. Defer until undraft + CI.

Run §28986426320

Generated by 🔧 PR Triage Agent · 74.6 AIC · ⌖ 8.8 AIC · ⊞ 5.4K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[performance] Regression in CompileMemoryUsage: +124.0% slower

2 participants