63c91cae5 moved the request path's key checks with a literal needle to
bodyHas. A profile of BenchmarkLargeRequest at that head still had
bytes.Contains at ~14% of the gateway's CPU: the checks whose needle is
kept as a []byte (openaiOnly in forVendor alone took 0.49s of 6.8s,
cacheControlField, thinkingType, toolUseType, the Gemini signature
fields, contentParts), and those built as []byte(`"`+f+`"`). They go
through bodyHasBytes/bodyHas now, and the stream's bytes.Index loops
(turndone, refusal_handover, routing) through bodyIndexBytes; a line
under 1 KB takes strings.Index as before.
grokToolPatterns asked gjson for the model before it looked for a
"pattern" at all, so every request to every provider walked the body
to its model (0.43s of the same profile; Responses bodies carry the
model after the conversation). The pattern check now goes first; the
answer is the same, since both had to hold.
anthropic_shapes copied a tool_result's raw content into a []byte to
look in it; it uses strings.Contains on the string.
BenchmarkLargeRequest on mica, 200x, before -> after:
anthropic 23.0 -> 21.9 ms
anthropic-group 24.2 -> 22.9 ms
chat 29.0 -> 28.4 ms
responses 26.8 -> 22.8 ms
Run (mica, at this head): gofmt -l clean, go vet ./internal/gateway for
darwin, linux and windows, the benchmark above, go test -count=1 ./internal/gateway ok (860s). bodyIndex is held to
bytes.Index by TestBodyIndexIsIndex (63c91cae5).
Real account: the built app (mote, sandbox HOME) sent a 6KB request to
DeepSeek on /v1/responses and /v1/messages, both 200 "pong". Not tried:
Codex and Grok (the sandbox's Codex sign-in is stale; renewing it there
would rotate the live refresh token).