perf: add capacity hints to slice allocations
Pre-allocate slices where upper bounds are known: config matches, migration results, skill search results, search cache, telegram table extraction, and skill listing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b9a0677572
commit
66c5f2d897
6 changed files with 8 additions and 8 deletions
|
|
@ -833,7 +833,7 @@ func extractInlineCodes(text string) inlineCodeMatch {
|
|||
func extractMarkdownTables(text string) tableBlockMatch {
|
||||
lines := strings.Split(text, "\n")
|
||||
out := make([]string, 0, len(lines))
|
||||
tables := make([]string, 0)
|
||||
tables := make([]string, 0, 4)
|
||||
placeholderIdx := 0
|
||||
|
||||
for i := 0; i < len(lines); {
|
||||
|
|
@ -845,7 +845,7 @@ func extractMarkdownTables(text string) tableBlockMatch {
|
|||
}
|
||||
block := lines[start:i]
|
||||
formatted := formatMarkdownTable(block)
|
||||
placeholder := fmt.Sprintf("\x00TB%d\x00", placeholderIdx)
|
||||
placeholder := "\x00TB" + strconv.Itoa(placeholderIdx) + "\x00"
|
||||
placeholderIdx++
|
||||
tables = append(tables, formatted)
|
||||
out = append(out, placeholder)
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ func (c *Config) GetModelConfig(modelName string) (*ModelConfig, error) {
|
|||
|
||||
// findMatches finds all ModelConfig entries with the given model_name.
|
||||
func (c *Config) findMatches(modelName string) []ModelConfig {
|
||||
var matches []ModelConfig
|
||||
matches := make([]ModelConfig, 0, 4)
|
||||
for i := range c.ModelList {
|
||||
if c.ModelList[i].ModelName == modelName {
|
||||
matches = append(matches, c.ModelList[i])
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig {
|
|||
|
||||
p := cfg.Providers
|
||||
|
||||
var result []ModelConfig
|
||||
result := make([]ModelConfig, 0, 20)
|
||||
|
||||
// Track if we've applied the legacy model name fix (only for first provider)
|
||||
legacyModelNameApplied := false
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func NewSkillsLoader(workspace string, globalSkills string, builtinSkills string
|
|||
}
|
||||
|
||||
func (sl *SkillsLoader) ListSkills() []SkillInfo {
|
||||
skills := make([]SkillInfo, 0)
|
||||
skills := make([]SkillInfo, 0, 20)
|
||||
|
||||
if sl.workspaceSkills != "" {
|
||||
if dirs, err := os.ReadDir(sl.workspaceSkills); err == nil {
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ func (rm *RegistryManager) SearchAll(ctx context.Context, query string, limit in
|
|||
close(resultsCh)
|
||||
}()
|
||||
|
||||
var merged []SearchResult
|
||||
merged := make([]SearchResult, 0, len(regs)*limit)
|
||||
var lastErr error
|
||||
|
||||
var anyRegistrySucceeded bool
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ func NewSearchCache(maxEntries int, ttl time.Duration) *SearchCache {
|
|||
ttl = 5 * time.Minute
|
||||
}
|
||||
return &SearchCache{
|
||||
entries: make(map[string]*cacheEntry),
|
||||
order: make([]string, 0),
|
||||
entries: make(map[string]*cacheEntry, maxEntries),
|
||||
order: make([]string, 0, maxEntries),
|
||||
maxEntries: maxEntries,
|
||||
ttl: ttl,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue