Skip to content

perf: cache builtin alias map and DFS cycle-check to fix CompileMCPWorkflow regression#44996

Draft
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compile-mcp-workflow-performance
Draft

perf: cache builtin alias map and DFS cycle-check to fix CompileMCPWorkflow regression#44996
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-compile-mcp-workflow-performance

Conversation

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

BenchmarkCompileMCPWorkflow regressed +14% (432µs vs 379µs). Two hot paths were doing redundant work on every compilation: BuiltinModelAliases() deep-copied the 52-entry builtin map on every call, and detectCircularModelAliases ran a full DFS over all 52 builtin keys even though builtins are immutable and cycle-free.

model_aliases.go

  • Added builtinOnlyAliasMap() backed by sync.Once returning a cached shared reference to the merged builtin map
  • MergeImportedModelAliases(nil, nil) — the common case for MCP workflows with no imports — now returns the cached reference instead of deep-copying

model_alias_validation.go

  • detectCircularModelAliases uses a new isBuiltinOnlyAliasMap helper (key-set equality, not just length) to detect when the input is the builtin-only map
  • When builtin-only, DFS runs once via sync.Once and the result is cached for all subsequent calls
  • loadBuiltinModelAliases() errors are now logged with a fallback to full DFS instead of being silently discarded
  • Cached DFS call passes empty markdownPath to avoid embedding a stale caller path in a shared error

Result: ~291–306µs vs reported 432µs (~30% faster); 80 fewer allocs/op, ~10KB less memory per compilation.

…Workflow speedup

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix regression in CompileMCPWorkflow performance perf: cache builtin alias map and DFS cycle-check to fix CompileMCPWorkflow regression Jul 11, 2026
Copilot AI requested a review from pelikhan July 11, 2026 18:09
@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category refactor (perf)
Risk 🟡 Medium
Score 58/100 (Impact 28 + Urgency 15 + Quality 15)
Action 🔄 batch_review
CI ⚪ Unknown (draft, no checks yet)
Batch perf-regressions (with #44994, #44995)

Draft PR — part of perf regression batch. Review together with #44994 and #44995.

Generated by 🔧 PR Triage Agent · 180.8 AIC · ⌖ 7.62 AIC · ⊞ 5.6K ·

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category refactor / perf
Risk 🟡 medium
Score 45/100 (impact:22 + urgency:13 + quality:10)
Action 📦 batch_review
Batch pr-batch:perf-regressions (with #44994, #44995)

Rationale: Draft. Caches builtin alias map and DFS cycle-check to fix CompileMCPWorkflow +14% regression. Small change. Batch with other perf PRs.

Triage run §29183606049

Generated by 🔧 PR Triage Agent · 171.6 AIC · ⌖ 5.63 AIC · ⊞ 5.6K ·

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 CompileMCPWorkflow: +14.0% slower

2 participants