Skip to content

Reduce ExtractWorkflowNameFromFile overhead in CLI workflow title parsing#44604

Merged
pelikhan merged 3 commits into
mainfrom
copilot/improve-extract-workflow-name-performance
Jul 10, 2026
Merged

Reduce ExtractWorkflowNameFromFile overhead in CLI workflow title parsing#44604
pelikhan merged 3 commits into
mainfrom
copilot/improve-extract-workflow-name-performance

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

ExtractWorkflowNameFromFile showed a measurable regression versus historical benchmark levels, with time spent in line-by-line title extraction. This change tightens the hot path in fastParseTitleFromReader to reduce per-line work without altering parsing behavior.

  • Hot-path optimization in title scanning

    • Switched scanner processing from string-based operations to byte-slice operations.
    • Replaced scanner.Text() + strings.TrimSpace/HasPrefix with scanner.Bytes() + bytes.TrimSpace/HasPrefix/Equal.
    • Preserves existing semantics for frontmatter detection (---) and H1 extraction (# ), while reducing transient allocations.
  • Scope and behavior

    • Changes are isolated to /pkg/cli/workflows.go in fastParseTitleFromReader.
    • No changes to workflow name fallback rules or frontmatter error behavior.
trimmed := bytes.TrimSpace(scanner.Bytes())

if bytes.Equal(trimmed, frontmatterDelimiter) { ... }
if bytes.HasPrefix(trimmed, h1Prefix) {
    return string(bytes.TrimSpace(trimmed[2:])), nil
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix regression in ExtractWorkflowNameFromFile performance Reduce ExtractWorkflowNameFromFile overhead in CLI workflow title parsing Jul 9, 2026
Copilot AI requested a review from pelikhan July 9, 2026 18:44
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

PR Triage - Run 29041860272. Category: chore | Risk: Low | Score: 28/100 | Action: defer. DRAFT. Micro hot-path optimization in ExtractWorkflowNameFromFile (8+/5-, 1 file). No behavior change. Undraft when ready; low priority.

Generated by 🔧 PR Triage Agent · 78.2 AIC · ⌖ 8.53 AIC · ⊞ 5.4K ·

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage — Run §29061171191

Field Value
Category chore
Risk 🟢 Low
Score 28/100 (Impact 10 + Urgency 8 + Quality 10)
Action 🔃 defer

Reduce ExtractWorkflowNameFromFile overhead. DRAFT, 1 file, 8 additions. Minor perf chore. Low priority.

Generated by 🔧 PR Triage Agent · 155.8 AIC · ⌖ 8.06 AIC · ⊞ 5.4K ·

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the performance optimization in fastParseTitleFromReader! Switching to byte-slice operations is a solid improvement that reduces transient allocations.

One suggestion before merging:

  • Add a benchmark test — since this fixes a measured regression, a BenchmarkExtractWorkflowNameFromFile in the test file would confirm the improvement and guard against future regressions.

If you would like a hand:

Add a benchmark test for ExtractWorkflowNameFromFile in pkg/cli/workflows_test.go (or a new _bench_test.go file).
Cover both frontmatter and H1 title extraction paths to confirm the byte-slice optimization reduces allocations.
Run with: go test -bench=. -benchmem ./pkg/cli/...

Generated by ✅ Contribution Check · 103.9 AIC · ⌖ 11.3 AIC · ⊞ 6.2K ·

@pelikhan pelikhan marked this pull request as ready for review July 10, 2026 04:01
Copilot AI review requested due to automatic review settings July 10, 2026 04:01
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot extract the first header h1, h2, or h3 as the title

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes CLI workflow title parsing by tightening the hot path in fastParseTitleFromReader, aiming to reduce per-line overhead in ExtractWorkflowNameFromFile without changing parsing semantics.

Changes:

  • Switched from scanner.Text() + strings.* operations to scanner.Bytes() + bytes.* operations to reduce transient allocations during line scanning.
  • Preserved existing behavior for frontmatter delimiter detection (---) and H1 title extraction (# ), while keeping early-exit scanning.
Show a summary per file
File Description
pkg/cli/workflows.go Reworks title scanning to operate on byte slices (bytes.TrimSpace/HasPrefix/Equal) instead of strings to reduce per-line work in the title extraction hot path.

Review details

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread pkg/cli/workflows.go
Comment on lines +358 to +359
frontmatterDelimiter := []byte("---")
h1Prefix := []byte("# ")
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot extract the first header h1, h2, or h3 as the title

Implemented in bf2f443. Title extraction now returns the first Markdown header among H1, H2, or H3 (while keeping existing frontmatter handling and filename fallback behavior), and tests were updated for H2/H3 and H4 fallback cases.

Copilot AI requested a review from pelikhan July 10, 2026 04:19
@pelikhan pelikhan merged commit d14ac73 into main Jul 10, 2026
29 checks passed
@pelikhan pelikhan deleted the copilot/improve-extract-workflow-name-performance branch July 10, 2026 04:52
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 ExtractWorkflowNameFromFile: 26.5% slower

3 participants