Skip to content

Commit 4578000

Browse files
perf: pre-allocate slice capacity in assistantMessageParam
Pre-allocate the `blocks` slice in `assistantMessageParam` with `make([]anthropic.ContentBlockParamUnion, 0, len(m.Parts))` to prevent multiple memory reallocations during `append` operations. Co-authored-by: matdev83 <211248003+matdev83@users.noreply.github.com>
1 parent 02325fe commit 4578000

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • internal/plugins/backends/protocols/anthropicmessages

internal/plugins/backends/protocols/anthropicmessages/invoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func assistantMessageParam(m lipapi.Message) (anthropic.MessageParam, error) {
170170
return anthropic.MessageParam{}, fmt.Errorf("anthropic: assistant message may only contain text parts in this adapter")
171171
}
172172
}
173-
var blocks []anthropic.ContentBlockParamUnion
173+
blocks := make([]anthropic.ContentBlockParamUnion, 0, len(m.Parts))
174174
for _, p := range m.Parts {
175175
if strings.TrimSpace(p.Text) == "" {
176176
continue

0 commit comments

Comments
 (0)