Problem
make(map[T]bool) is used as a set (tracking seen/visited items) throughout the codebase — 153+ non-test production files use this pattern. Meanwhile, map[T]struct{} is used in 14 production files for the same purpose, creating an inconsistency. Using bool values for set membership is less idiomatic Go and wastes memory: struct{} has zero size whereas bool is 1 byte per map entry.
The inconsistency originates from core utility functions that serve as patterns for the rest of the codebase:
pkg/sliceutil/sliceutil.go:64 — Deduplicate uses make(map[T]bool, len(slice))
pkg/workflow/validation_helpers.go:212 — validateNoDuplicateIDs uses make(map[string]bool)
pkg/stringutil/sanitize.go:22 — commonWorkflowKeywords declared as map[string]bool{...}
These three are referenced throughout the codebase and set the precedent for the map[...]bool pattern.
Impact
- Severity: Medium
- Affected Files: 153+ production Go files
- Risk: No correctness risk; purely idiomatic and memory efficiency gap
Recommendation
Migrate set-semantics maps to map[T]struct{}. Start with the utility functions that serve as patterns:
Before (pkg/sliceutil/sliceutil.go):
func Deduplicate[T comparable](slice []T) []T {
seen := make(map[T]bool, len(slice))
for _, item := range slice {
if !seen[item] {
seen[item] = true
After:
func Deduplicate[T comparable](slice []T) []T {
seen := make(map[T]struct{}, len(slice))
for _, item := range slice {
if _, ok := seen[item]; !ok {
seen[item] = struct{}{}
Similarly for validateNoDuplicateIDs and the commonWorkflowKeywords literal.
Validation
Estimated Effort: Medium (many files, but mechanical change)
Generated by Sergo - Serena Go Expert · ● 536.8K · ◷
Problem
make(map[T]bool)is used as a set (tracking seen/visited items) throughout the codebase — 153+ non-test production files use this pattern. Meanwhile,map[T]struct{}is used in 14 production files for the same purpose, creating an inconsistency. Usingboolvalues for set membership is less idiomatic Go and wastes memory:struct{}has zero size whereasboolis 1 byte per map entry.The inconsistency originates from core utility functions that serve as patterns for the rest of the codebase:
pkg/sliceutil/sliceutil.go:64—Deduplicateusesmake(map[T]bool, len(slice))pkg/workflow/validation_helpers.go:212—validateNoDuplicateIDsusesmake(map[string]bool)pkg/stringutil/sanitize.go:22—commonWorkflowKeywordsdeclared asmap[string]bool{...}These three are referenced throughout the codebase and set the precedent for the
map[...]boolpattern.Impact
Recommendation
Migrate set-semantics maps to
map[T]struct{}. Start with the utility functions that serve as patterns:Before (
pkg/sliceutil/sliceutil.go):After:
Similarly for
validateNoDuplicateIDsand thecommonWorkflowKeywordsliteral.Validation
go test ./pkg/sliceutil/...after changingDeduplicatego test ./pkg/workflow/...after changingvalidateNoDuplicateIDsgo test ./pkg/stringutil/...after changingcommonWorkflowKeywordsgrep -r "make(map\[string\]bool" pkg/to track remaining occurrencesEstimated Effort: Medium (many files, but mechanical change)