Skip to content

Improve performance: fix defer-in-loop leaks, eliminate redundant operations, add container caching#152

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/identify-slow-code-issues
Draft

Improve performance: fix defer-in-loop leaks, eliminate redundant operations, add container caching#152
Copilot wants to merge 3 commits intomainfrom
copilot/identify-slow-code-issues

Conversation

Copy link

Copilot AI commented Nov 25, 2025

Identified and fixed multiple performance issues and resource leaks across Dagger modules.

Container Setup Optimization

  • helm/container.go: Removed duplicate apk add call, added temp file cleanup after tool installations, added container caching via cachedContainer field
  • git/container.go: Combined 6 individual sh -c commands into single script
  • kcl/container.go: Combined apt-get update && install with --no-install-recommends and apt cache cleanup
  • linting/container.go: Combined gem install and pip install into single command with --no-cache-dir

Duplicate Work Elimination

  • go/test.go: Was running tests twice (once with -v, once with -cover). Now runs once with both flags.
// Before: ran tests twice
testOutput, _ := container.WithExec([]string{"go", "test", "-v", testArg}).Stdout(ctx)
coverageOutput, _ := container.WithExec([]string{"go", "test", "-cover", testArg}).Stdout(ctx)

// After: single pass
testOutput, err := container.WithExec([]string{"go", "test", "-v", "-cover", testArg}).Stdout(ctx)

Resource Leak Fixes

  • hugo/helpers.go: Fixed defer-in-loop bug in downloadImages() - defers were accumulating until function return
  • templating/file.go, string.go: Same defer-in-loop fix, extracted downloadURLContent() helper
// Before: defer inside loop accumulates calls
for _, url := range urls {
    resp, _ := http.Get(url)
    defer resp.Body.Close()  // BUG: defers pile up
}

// After: helper function scopes defer correctly
func downloadSingleImage(url, destDir string) error {
    resp, _ := http.Get(url)
    defer resp.Body.Close()  // OK: runs at helper return
    // ...
}

Bug Fixes

  • ansible/container.go: baseImage parameter was being ignored in favor of hardcoded value
Original prompt

Identify and suggest improvements to slow or inefficient code


💡 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.

Copilot AI and others added 2 commits November 25, 2025 20:24
…oop bugs, add container caching

Co-authored-by: patrick-hermann-sva <47567770+patrick-hermann-sva@users.noreply.github.com>
Co-authored-by: patrick-hermann-sva <47567770+patrick-hermann-sva@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow code Improve performance: fix defer-in-loop leaks, eliminate redundant operations, add container caching Nov 25, 2025
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.

2 participants