Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
## 2024-10-25 - Avoid mime.ParseMediaType for exact header matching
**Learning:** Using `mime.ParseMediaType` for exact or prefix header matching in hot paths introduces unnecessary memory allocations.
**Action:** When substituting with `strings.HasPrefix`, explicitly handle case-insensitivity (e.g., via `strings.ToLower`) to maintain HTTP standard compliance while preventing heavy parsing allocations.

## 2024-10-25 - Avoid strings.ToLower for case-insensitive prefix matching
**Learning:** Using `strings.ToLower` for case-insensitive prefix matching forces a memory allocation. In hot paths, this creates unnecessary garbage collection overhead.
**Action:** Use `len(str) >= len(prefix) && strings.EqualFold(str[:len(prefix)], prefix)` to achieve zero-allocation case-insensitive matching.
5 changes: 3 additions & 2 deletions cmd/sergeant-mcp-client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ func (p *proxy) writeResponse(resp *response) {
return
}

// Performance optimization: Avoid mime.ParseMediaType allocation for exact header matching
isEventStream := strings.HasPrefix(strings.ToLower(resp.contentType), "text/event-stream")
// Performance optimization: Avoid mime.ParseMediaType and strings.ToLower allocations for prefix header matching
prefix := "text/event-stream"
isEventStream := len(resp.contentType) >= len(prefix) && strings.EqualFold(resp.contentType[:len(prefix)], prefix)
p.outMu.Lock()
defer p.outMu.Unlock()
if isEventStream {
Expand Down
Loading