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
b889617373
commit
7a3e6b0543
6 changed files with 8 additions and 8 deletions
|
|
@ -833,7 +833,7 @@ func extractInlineCodes(text string) inlineCodeMatch {
|
||||||
func extractMarkdownTables(text string) tableBlockMatch {
|
func extractMarkdownTables(text string) tableBlockMatch {
|
||||||
lines := strings.Split(text, "\n")
|
lines := strings.Split(text, "\n")
|
||||||
out := make([]string, 0, len(lines))
|
out := make([]string, 0, len(lines))
|
||||||
tables := make([]string, 0)
|
tables := make([]string, 0, 4)
|
||||||
placeholderIdx := 0
|
placeholderIdx := 0
|
||||||
|
|
||||||
for i := 0; i < len(lines); {
|
for i := 0; i < len(lines); {
|
||||||
|
|
@ -845,7 +845,7 @@ func extractMarkdownTables(text string) tableBlockMatch {
|
||||||
}
|
}
|
||||||
block := lines[start:i]
|
block := lines[start:i]
|
||||||
formatted := formatMarkdownTable(block)
|
formatted := formatMarkdownTable(block)
|
||||||
placeholder := fmt.Sprintf("\x00TB%d\x00", placeholderIdx)
|
placeholder := "\x00TB" + strconv.Itoa(placeholderIdx) + "\x00"
|
||||||
placeholderIdx++
|
placeholderIdx++
|
||||||
tables = append(tables, formatted)
|
tables = append(tables, formatted)
|
||||||
out = append(out, placeholder)
|
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.
|
// findMatches finds all ModelConfig entries with the given model_name.
|
||||||
func (c *Config) findMatches(modelName string) []ModelConfig {
|
func (c *Config) findMatches(modelName string) []ModelConfig {
|
||||||
var matches []ModelConfig
|
matches := make([]ModelConfig, 0, 4)
|
||||||
for i := range c.ModelList {
|
for i := range c.ModelList {
|
||||||
if c.ModelList[i].ModelName == modelName {
|
if c.ModelList[i].ModelName == modelName {
|
||||||
matches = append(matches, c.ModelList[i])
|
matches = append(matches, c.ModelList[i])
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig {
|
||||||
|
|
||||||
p := cfg.Providers
|
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)
|
// Track if we've applied the legacy model name fix (only for first provider)
|
||||||
legacyModelNameApplied := false
|
legacyModelNameApplied := false
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func NewSkillsLoader(workspace string, globalSkills string, builtinSkills string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *SkillsLoader) ListSkills() []SkillInfo {
|
func (sl *SkillsLoader) ListSkills() []SkillInfo {
|
||||||
skills := make([]SkillInfo, 0)
|
skills := make([]SkillInfo, 0, 20)
|
||||||
|
|
||||||
if sl.workspaceSkills != "" {
|
if sl.workspaceSkills != "" {
|
||||||
if dirs, err := os.ReadDir(sl.workspaceSkills); err == nil {
|
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)
|
close(resultsCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var merged []SearchResult
|
merged := make([]SearchResult, 0, len(regs)*limit)
|
||||||
var lastErr error
|
var lastErr error
|
||||||
|
|
||||||
var anyRegistrySucceeded bool
|
var anyRegistrySucceeded bool
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ func NewSearchCache(maxEntries int, ttl time.Duration) *SearchCache {
|
||||||
ttl = 5 * time.Minute
|
ttl = 5 * time.Minute
|
||||||
}
|
}
|
||||||
return &SearchCache{
|
return &SearchCache{
|
||||||
entries: make(map[string]*cacheEntry),
|
entries: make(map[string]*cacheEntry, maxEntries),
|
||||||
order: make([]string, 0),
|
order: make([]string, 0, maxEntries),
|
||||||
maxEntries: maxEntries,
|
maxEntries: maxEntries,
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue