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.
## 2024-10-25 - Avoid mime.ParseMediaType in hot paths
**Learning:** Using `mime.ParseMediaType` for exact or prefix header matching (e.g., checking for `text/event-stream`) causes unnecessary memory allocations and parsing overhead in Go hot paths.
**Action:** Use `strings.HasPrefix` (combined with `strings.ToLower` if case insensitivity is needed) instead to prevent these allocations and reduce CPU overhead.
8 changes: 5 additions & 3 deletions cmd/sergeant-mcp-client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"mime"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -175,10 +174,13 @@ func (p *proxy) writeResponse(resp *response) {
return
}

mediaType, _, _ := mime.ParseMediaType(resp.contentType)
// Optimization: Use strings.HasPrefix instead of mime.ParseMediaType to prevent
// unnecessary memory allocations and parsing overhead in this hot path.
// We use strings.ToLower to correctly handle case-insensitive header matching.
// Expected impact: Eliminates a memory allocation per proxy response.
p.outMu.Lock()
defer p.outMu.Unlock()
if mediaType == "text/event-stream" {
if strings.HasPrefix(strings.ToLower(resp.contentType), "text/event-stream") {
for _, data := range parseSSEData(resp.body) {
fmt.Fprintf(p.stdout, "%s\n", data)
}
Expand Down
Loading