@@ -11,6 +11,7 @@ import (
1111 "path/filepath"
1212 "strconv"
1313 "strings"
14+ "sync"
1415
1516 "github.com/github/gh-aw/pkg/console"
1617 "github.com/github/gh-aw/pkg/constants"
@@ -23,6 +24,14 @@ import (
2324
2425var workflowsLog = logger .New ("cli:workflows" )
2526
27+ const workflowTitleScannerBufferSize = 4 * 1024
28+
29+ var workflowTitleScannerBufferPool = sync.Pool {
30+ New : func () any {
31+ return make ([]byte , workflowTitleScannerBufferSize )
32+ },
33+ }
34+
2635func getWorkflowsDir () string {
2736 return ".github/workflows"
2837}
@@ -335,11 +344,16 @@ func filterMarkdownFilesWithFrontmatter(mdFiles []string) ([]string, error) {
335344// Returns an error if frontmatter is opened but never closed.
336345func fastParseTitleFromReader (r io.Reader ) (string , error ) {
337346 scanner := bufio .NewScanner (r )
338- // Use a small initial buffer (4 KB, matching the default scanner allocation)
339- // but allow growth up to 1 MB to handle files with large frontmatter values
340- // or long base64-encoded lines. Keeping the initial size small avoids a
341- // costly 64 KB heap allocation on every call.
342- scanner .Buffer (make ([]byte , 4 * 1024 ), 1024 * 1024 )
347+ // Reuse the small initial scanner buffer across calls while still allowing
348+ // growth up to 1 MB for large frontmatter values or long base64-encoded lines.
349+ scannerBuffer := workflowTitleScannerBufferPool .Get ().([]byte )
350+ if cap (scannerBuffer ) != workflowTitleScannerBufferSize {
351+ scannerBuffer = make ([]byte , workflowTitleScannerBufferSize )
352+ } else {
353+ scannerBuffer = scannerBuffer [:workflowTitleScannerBufferSize ]
354+ }
355+ defer workflowTitleScannerBufferPool .Put (scannerBuffer )
356+ scanner .Buffer (scannerBuffer , 1024 * 1024 )
343357 firstLine := true
344358 inFrontmatter := false
345359 for scanner .Scan () {
0 commit comments