Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mcp/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ func writeEvent(w http.ResponseWriter, evt Event) (int, error) {
if evt.Retry != "" {
fmt.Fprintf(&b, "retry: %s\n", evt.Retry)
}
fmt.Fprintf(&b, "data: %s\n\n", string(evt.Data))
// Write the payload directly into a pre-grown buffer to avoid the extra
// copy from string(evt.Data) and repeated buffer regrowths.
b.Grow(len("data: \n\n") + len(evt.Data))
b.WriteString("data: ")
b.Write(evt.Data)
b.WriteString("\n\n")
n, err := w.Write(b.Bytes())
rc := http.NewResponseController(w)
// Ignore returned error as flushing is best-effort.
Expand Down
Loading