Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
**Action:** Use `strings.NewReader(str)` directly instead of `bytes.NewReader([]byte(str))` to eliminate the allocation overhead.
## 2026-09-11 - Memoize Dynamic Library Load (`ctypes.CDLL`)
**Learning:** Found that `ctypes.CDLL(None, use_errno=True)` within `pidfd_open` and `pidfd_send_signal` fallback paths in `_sgt-process-token.py` re-loaded the C library dynamically on every call, causing measurable per-call overhead, analogous to the learning about `libc_pidfd_function` from 2024-08-27.
**Action:** Substituted the redundant inline `ctypes.CDLL` loads with the memoized module-level `_LIBC_WITH_ERRNO` global to eliminate repeated linking overhead.
**Action:** Substituted the redundant inline `ctypes.CDLL` loads with the memoized module-level `_LIBC_WITH_ERRNO` global to eliminate repeated linking overhead.
## 2026-09-20 - Avoid mime.ParseMediaType for header matching in hot paths
**Learning:** Using `mime.ParseMediaType` forces memory allocations due to string splitting and map creation, slowing down hot paths like response stream parsing.
**Action:** Use `strings.HasPrefix(strings.ToLower(strings.TrimSpace(header)), target)` instead of `mime.ParseMediaType` when checking content types to prevent allocation overhead, ensuring standard compliance through case-insensitivity.
6 changes: 3 additions & 3 deletions cmd/sergeant-mcp-client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"fmt"
"io"
"mime"

"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -175,10 +175,10 @@ func (p *proxy) writeResponse(resp *response) {
return
}

mediaType, _, _ := mime.ParseMediaType(resp.contentType)
p.outMu.Lock()
defer p.outMu.Unlock()
if mediaType == "text/event-stream" {
// Use strings.HasPrefix on lowercased header instead of mime.ParseMediaType to prevent allocation overhead
if strings.HasPrefix(strings.ToLower(strings.TrimSpace(resp.contentType)), "text/event-stream") {
for _, data := range parseSSEData(resp.body) {
fmt.Fprintf(p.stdout, "%s\n", data)
}
Expand Down
Loading