Draft
perf: fix ParseWorkflow regression (+29% → -51%) via targeted caching#44994
Conversation
- model_aliases.go: add isBuiltinOnlyAliasMap() using reflect.ValueOf().Pointer() for map identity check, plus builtinOnlyAliasMapID uintptr cache variable; MergeImportedModelAliases returns shared builtin map (no deep copy) when no imports/overrides present - avoids 154 string slice allocations per call - model_alias_validation.go: detectCircularModelAliases() fast-path caches DFS result for builtin-only map via builtinCycleCheckOnce (fixes invalid map==map comparison by using isBuiltinOnlyAliasMap() instead) - tools_parser.go: promote knownTools from local map literal to package-level variable to avoid 14-entry map allocation on every NewTools() call - template_validation.go: add strings.Contains fast-paths to three validation functions so they skip regex entirely for markdown with no template blocks Benchmark: 479μs (regression) → 235μs (local, -51%) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… cached error path - model_aliases.go: replace reflect.ValueOf().Pointer() with mapHeaderPointer() using unsafe.Pointer extraction; avoids reflection overhead on every call; remove redundant getBuiltinOnlyAliasMap() call from isBuiltinOnlyAliasMap() - model_alias_validation.go: pass empty path to builtin cycle check so a hypothetical cached error does not expose a caller's workflow path Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- model_aliases.go: expand mapHeaderPointer comment with Go version stability
note; expand MergeImportedModelAliases doc with prominent immutability warning
using ⚠ symbol
- model_alias_validation.go: use sentinel '<builtin-aliases>' path in builtin
cycle check instead of empty string for clearer hypothetical error messages
- template_validation.go: add comment explaining why '{{#if' is the correct
fast-path substring (templateRegionPattern exclusively matches {{#if blocks)
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix performance regression in ParseWorkflow
perf: fix ParseWorkflow regression (+29% → -51%) via targeted caching
Jul 11, 2026
Contributor
🤖 PR Triage
Draft PR — largest of the perf batch (132 additions, 4 files). Unmark draft and ensure CI passes before merging.
|
Contributor
🤖 PR Triage
Rationale: Draft. Fixes ParseWorkflow +29% regression via targeted caching. Good approach; batch with other perf PRs for efficient review. Triage run §29183606049
|
Contributor
🤖 PR Triage
Draft. ParseWorkflow caching improvement. +132/-20. Review in perf-regressions batch.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParseWorkflowregressed from 371μs to 479μs (+29.2%) due to three per-call allocations that were unnecessary for the common case (no imports, no custom model aliases).Root causes & fixes
MergeImportedModelAliases— 5KB deep copy on every call (model_aliases.go)ParseWorkflowFileinvocation, even whenimportedModelsandfrontmatterModelswere both empty (the overwhelmingly common case)getBuiltinOnlyAliasMap()returning a shared read-only singleton;MergeImportedModelAliasesreturns it directly when both inputs are emptymapHeaderPointer()viaunsafe.Pointer+isBuiltinOnlyAliasMap()for zero-overhead map identity comparison (Go disallowsmap == map)detectCircularModelAliases— 52-node DFS on every call (model_alias_validation.go)builtinCycleCheckOnce; runs at most once per process lifetime when the map is the shared builtinNewTools— 14-entry map literal allocated per call (tools_parser.go)knownToolsmap literal was re-created insideNewTools()on every invocationTemplate validation — regex executed on all markdown (
template_validation.go)FindAllStringSubmatchunconditionallystrings.Contains("{{#if")/strings.Contains("{{#")fast-paths to skip regex when no template blocks are presentResult
~50% faster than the regression; ~35% faster than the historical baseline.