Files
magpie/internal
yetone ccb75030aa gateway: a held request body is known by where it is, not summed again (#4371)
Each of the dozen decodes, topMember reads and validity checks a request
body goes through summed all its bytes with maphash to find what
validMemo knew of it: about 5% of the gateway's CPU on long Codex
requests (#4371). A body being served (holdBody) is not written while
held, so longBody and jsonValid now know it by its address and length,
check and split it once, and keep that in heldBodies.long until it is
released, as factsOf keeps its facts. Any other long body is summed as
before.

Run on mote at this tree:
- gofmt, go vet (darwin, GOOS=windows, GOOS=linux): ok
- TestHeldBodyIsNotSummed, TestHeldBodyNotJSON, TestDecodeJSON*,
  TestRequestBodyRawValuesShareIt, TestTopMember*, TestWithoutTopMember*:
  ok 3 of 3 alone, ok under -race
- go test -timeout 45m ./internal/gateway: ok (609s)
- Broken by hand: held lookup skipped -> "a held 84077-byte body was
  summed 18 times"; release left the finds kept -> "a released body's
  finds were kept".
- BenchmarkHeldBodyDecodes (1.8MB Responses body held, 12 decodes plus 12
  topMember reads an op): 3.31ms/op before, 7.9us/op after, allocations
  the same (24/op).

Real use: sandbox HOME copied from the owner's, real DeepSeek account,
deepseek-flash, four turns of a 115-123KB history through
/v1/chat/completions with masking on: every reply HTTP 200 (three "ok",
one empty at finish_reason length, the model's reasoning using
max_tokens, as on the old binary).

Not run: the full ./... suite; a real Codex account; Windows and Linux
runs of the tests.

Picked onto 9162277b9 (3 commits, none in internal/gateway/fastjson.go); not run again there.
2026-11-01 09:59:21 +08:00
..
…
…
…
…
…