mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-12-05 00:47:15 +08:00
Avoid full-payload copies when evaluating payload rules and reading HTTP
request bodies, cutting heap allocation amplification on multi-megabyte
base64 requests by >80% with zero behavioral changes:
- Evaluate single-item payload query predicates directly on ojson.Result
without copying item.Raw into a temporary "[...]" buffer (with exact
fallback for edge/malformed syntax).
- Resolve clean array "@reverse.<N>" paths via zero-copy ForEach traversal
instead of ojson.modReverse full-array cloning.
- Fast-path scalar, empty-container ([] / {}), and type-mismatch checks in
payloadResultEquals to skip moego/json.Unmarshal on large arrays, and use
bytes.TrimSpace in normalizedPayloadJSON.
- Cache compiled moego/regexp patterns in payload.replace with a bounded map.
- Release originalRequest in ClaudeInputTokenState once disabled or handled,
and only retain replayRequestPayload in Antigravity stream when replayScope
is valid.
- Preallocate raw request body buffers from Content-Length (capped at 4 MiB)
in ReadRawRequestBody to avoid io.ReadAll slice-doubling copies.