Skip to content

Replace redundant zero-capacity slice allocations with idiomatic zero-value declarations#12190

Merged
pelikhan merged 2 commits intomainfrom
copilot/eliminate-redundant-slice-allocations
Jan 28, 2026
Merged

Replace redundant zero-capacity slice allocations with idiomatic zero-value declarations#12190
pelikhan merged 2 commits intomainfrom
copilot/eliminate-redundant-slice-allocations

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Replace make([]T, 0) with var slice []T across 8 instances in the workflow compilation pipeline. Zero-value slices are idiomatic Go and eliminate unnecessary allocations.

Changes

  • pkg/workflow/action_cache.go: 3 slices (toDelete, deduplicationDetails, removedVersions)
  • pkg/workflow/jobs.go: 2 slices (jobOrder initialization removed, queue)
  • pkg/workflow/mcp_setup_generator.go: 1 slice (envVarNames)
  • pkg/workflow/compiler_safe_outputs_job.go: 1 slice (newSteps)
  • pkg/workflow/step_order_validation.go: 1 slice (steps initialization removed)

Before:

envVarNames := make([]string, 0)
for _, name := range vars {
    envVarNames = append(envVarNames, name)
}

After:

var envVarNames []string
for _, name := range vars {
    envVarNames = append(envVarNames, name)
}

No behavior change—nil slices work identically with append.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Eliminate redundant zero-capacity slice allocations</issue_title>
<issue_description>## Objective

Replace 10 instances of redundant make([]T, 0) allocations with idiomatic zero-value slices.

Context

From discussion githubnext/gh-aw#12006: Sergo analysis found explicit zero-capacity slice allocations that are less idiomatic and create unnecessary overhead. Zero-value slices work perfectly with append and are the Go convention.

Files to Modify

  • pkg/workflow/mcp_setup_generator.go:607
  • pkg/workflow/jobs.go:48, 432
  • pkg/workflow/action_cache.go:241, 242, 279
  • pkg/workflow/compiler_safe_outputs_job.go:372
  • pkg/workflow/step_order_validation.go:42

Approach

Replace patterns like:

envVarNames := make([]string, 0)
for _, name := range vars {
    envVarNames = append(envVarNames, name)
}

With idiomatic Go:

var envVarNames []string
for _, name := range vars {
    envVarNames = append(envVarNames, name)
}

Acceptance Criteria

  • All 10 instances replaced with zero-value slice declarations
  • All existing tests pass
  • Code passes go vet and golangci-lint
  • No behavior changes (nil slices work identically with append)

AI generated by Plan Command for discussion #12006

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…arations

- Replace `make([]string, 0)` with `var slice []string` in 8 locations
- Affected files: action_cache.go (3), jobs.go (2), mcp_setup_generator.go (1), compiler_safe_outputs_job.go (1), step_order_validation.go (1)
- No behavior changes (nil slices work identically with append)
- All tests pass, code formatted and linted

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Eliminate redundant zero-capacity slice allocations Replace redundant zero-capacity slice allocations with idiomatic zero-value declarations Jan 28, 2026
Copilot AI requested a review from pelikhan January 28, 2026 06:15
@pelikhan pelikhan marked this pull request as ready for review January 28, 2026 06:15
@github-actions
Copy link
Contributor

🔍 PR Triage Results

Category: refactor | Risk: low | Priority: 43/100

Scores Breakdown

  • Impact: 22/50 - Code quality improvement through idiomatic Go conventions
  • Urgency: 12/30 - Very recent PR (<1 hour old), CI showing some feedback
  • Quality: 9/20 - Draft status, CI unstable but providing feedback

📋 Recommended Action: defer

Rationale: This PR is in draft state and should remain deferred until marked ready for review. The changes are low-risk (only 16 lines changed across 5 files) and improve code quality by replacing make([]T, 0) with idiomatic zero-value slices. Once out of draft, this will be a good candidate for fast-track review given its focused scope and clear benefits.

Next steps: Mark as ready for review when CI is stable and all acceptance criteria are met.


Triaged by PR Triage Agent on 2026-01-28

AI generated by PR Triage Agent

@pelikhan pelikhan merged commit 8ef509b into main Jan 28, 2026
157 of 158 checks passed
@pelikhan pelikhan deleted the copilot/eliminate-redundant-slice-allocations branch January 28, 2026 06:26
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.

[plan] Eliminate redundant zero-capacity slice allocations

2 participants