Skip to content

Reduce alloc by 1 in mergeAndDedupActions#686

Merged
majewsky merged 1 commit intomasterfrom
scopeset
Apr 9, 2026
Merged

Reduce alloc by 1 in mergeAndDedupActions#686
majewsky merged 1 commit intomasterfrom
scopeset

Conversation

@SuperSandro2000
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/sapcc/keppel/internal/auth 88.63% (+0.05%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/sapcc/keppel/internal/auth/scopeset.go 97.62% (+0.12%) 462 (+22) 451 (+22) 11 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/sapcc/keppel/internal/auth/scopeset_test.go

@majewsky majewsky merged commit 1ab9b8e into master Apr 9, 2026
7 of 8 checks passed
@majewsky majewsky deleted the scopeset branch April 9, 2026 14:30
Copy link
Copy Markdown
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

This PR optimizes scope action merging in internal/auth to reduce allocations during ScopeSet.Add() merges, and adds a benchmark to measure NewScopeSet allocation behavior.

Changes:

  • Reworked mergeAndDedupActions to avoid allocating a combined slice when iterating lhs+rhs.
  • Added BenchmarkNewScopeSet to track allocations for common scope combinations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/auth/scopeset.go Refactors action merge/dedup logic to reduce allocations by appending directly to lhs.
internal/auth/scopeset_test.go Adds a benchmark for NewScopeSet allocation tracking.

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

Comment on lines +48 to +52
func mergeAndDedupActions(lhs, rhs []string) []string {
seen := make(map[string]bool, len(lhs))
for _, elem := range lhs {
seen[elem] = true
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

mergeAndDedupActions no longer actually deduplicates elements already present in lhs. The previous implementation removed duplicates across lhs+rhs by building a fresh result while tracking seen; the new implementation seeds seen from lhs but then returns lhs unchanged (except for appends from rhs), so any duplicates already in lhs remain. This is a behavior change that can surface if the first scope for a resource contains duplicated actions (e.g. a scope string like pull,pull). Consider rebuilding lhs in-place (or into a new slice) while checking seen for lhs entries as well, to preserve the original dedup semantics while still avoiding the append(lhs, rhs...) allocation.

Copilot uses AI. Check for mistakes.
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.

3 participants