perf: pre-compile glob patterns in config filter matching
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- go
- Domain
- cli, performance
Research direction
Start by reading generator.go:117-158, especially matchAnyName and the config filtering loop. Preserve the current exact and glob matching behavior while preparing pattern strings once; done means filtering results remain unchanged without repeated glob parsing or fmt.Sprint calls.
Written by the indexing model from the issue text.
Description
Summary
matchAnyName in generator.go:148-158 performs shell glob matching for every pattern on every interface/struct during config filtering:
matchAnyName := func(name string, patterns []any) bool {
name = filePkgPath + "." + stripGeneric(name)
for _, p := range patterns {
if stripGeneric(fmt.Sprint(p)) == name {
return true
}
if ok, _ := filepath.Match("*"+stripGeneric(fmt.Sprint(p)), filepath.Base(name)); ok {
return true
}
}
return false
}
Each call to filepath.Match parses the glob pattern from scratch. For 100 structs × 5 patterns, that's 500+ glob matches. fmt.Sprint(p) is also called twice per pattern iteration.
Proposed Fix
Pre-compile patterns once before the filtering loop:
type compiledPattern struct {
exact string // for exact match
glob string // for filepath.Match
}
Compile all patterns once, then match against the compiled list. Also cache fmt.Sprint(p) results.
Impact
Minor — only noticeable in monorepos with many structs/interfaces and many filter patterns. The O(n × m) matching is fine for typical use (5–20 types, 1–3 patterns), but pre-compilation is the right pattern for correctness and makes the code cleaner.
Note
The outer loop at generator.go:117-135 does O(files × configFiles) prefix matching. For typical CLI usage this is negligible, but if the codebase grows to support large monorepos with many config files, consider sorting config paths and using binary search for prefix matching.
- Dominant language
- Go
- Stars
- 109
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from go-gorm/cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100