Bolt: Optimize string building in message summary loop
Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
This commit is contained in:
parent
dbd89a41cb
commit
ba3fd0d3aa
1 changed files with 10 additions and 2 deletions
|
|
@ -323,8 +323,12 @@ func (al *AgentLoop) summarizeBatch(
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
}
|
}
|
||||||
sb.WriteString("\nCONVERSATION:\n")
|
sb.WriteString("\nCONVERSATION:\n")
|
||||||
|
// Bolt: Avoiding fmt.Fprintf overhead inside a hot loop by directly calling strings.Builder methods
|
||||||
for _, m := range batch {
|
for _, m := range batch {
|
||||||
fmt.Fprintf(&sb, "%s: %s\n", m.Role, m.Content)
|
sb.WriteString(m.Role)
|
||||||
|
sb.WriteString(": ")
|
||||||
|
sb.WriteString(m.Content)
|
||||||
|
sb.WriteString("\n")
|
||||||
}
|
}
|
||||||
prompt := sb.String()
|
prompt := sb.String()
|
||||||
|
|
||||||
|
|
@ -359,7 +363,11 @@ func (al *AgentLoop) summarizeBatch(
|
||||||
if keepLength < len(runes) {
|
if keepLength < len(runes) {
|
||||||
content += "..."
|
content += "..."
|
||||||
}
|
}
|
||||||
fallback.WriteString(fmt.Sprintf("%s: %s", m.Role, content))
|
|
||||||
|
// Bolt: Using multiple direct WriteString calls instead of fmt.Sprintf to avoid formatting overhead
|
||||||
|
fallback.WriteString(m.Role)
|
||||||
|
fallback.WriteString(": ")
|
||||||
|
fallback.WriteString(content)
|
||||||
}
|
}
|
||||||
return fallback.String(), nil
|
return fallback.String(), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue