Skip to content

perf: optimize extractWorkflowNameFromFile by eliminating unnecessary YAML parse#21012

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-performance-regression-extractworkflownamefrom
Mar 15, 2026
Merged

perf: optimize extractWorkflowNameFromFile by eliminating unnecessary YAML parse#21012
pelikhan merged 4 commits intomainfrom
copilot/fix-performance-regression-extractworkflownamefrom

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

extractWorkflowNameFromFile was calling parser.ExtractFrontmatterFromContent, which runs a full yaml.Unmarshal — entirely wasted work when the function only needs to skip the frontmatter block and scan for the first # header.

Changes

  • pkg/cli/workflows.go: Extracted the lightweight line-scanning logic into a new fastParseTitle(content string) (string, error) function. It skips frontmatter delimiters without YAML parsing and returns the first H1 title. Frontmatter is only recognised when --- appears on the first line (preserving original semantics). Unclosed frontmatter still returns an error. extractWorkflowNameFromFile now delegates to fastParseTitle.

  • pkg/cli/commands_utils_test.go: Added TestFastParseTitle with 10 table-driven test cases covering: H1 after frontmatter, trailing spaces, no frontmatter, H1 as first line, no H1 header, only H2 headers, empty content, unclosed frontmatter error, mid-content --- delimiter, and H1 inside a frontmatter block.

// fastParseTitle — no yaml.Unmarshal, no heap allocations from YAML parsing
func fastParseTitle(content string) (string, error) {
    // skips optional frontmatter block, returns first "# " header text
}

Benchmark: ~19,000 ns/op → ~11,500 ns/op (~40% improvement)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 14, 2026 21:46
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan March 15, 2026 01:47
@pelikhan pelikhan marked this pull request as ready for review March 15, 2026 01:56
Copilot AI review requested due to automatic review settings March 15, 2026 01:56
@pelikhan pelikhan merged commit c87077e into main Mar 15, 2026
51 checks passed
@pelikhan pelikhan deleted the copilot/fix-performance-regression-extractworkflownamefrom branch March 15, 2026 01:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves performance and resilience of workflow name extraction by scanning markdown for the first H1 header without fully parsing YAML frontmatter.

Changes:

  • Added fastParseTitle to quickly find the first # title while skipping optional frontmatter.
  • Updated extractWorkflowNameFromFile to use the fast title scanner instead of full frontmatter parsing.
  • Added unit tests covering fastParseTitle behavior across frontmatter/no-frontmatter and error cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/cli/workflows.go Introduces a lightweight markdown title scan and wires it into workflow name extraction.
pkg/cli/commands_utils_test.go Adds targeted unit tests validating title parsing behavior and edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[performance] Regression in ExtractWorkflowNameFromFile: +19.8% slower

3 participants