mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
The byte-level precheck added for #8668 still runs both cache_control walks for any body containing a "thinking" literal, because the thinking-block cleanup cannot be skipped by that check alone. Claude Code enables extended thinking by default, so that is the dominant shape: the precheck pays its own scan and then falls through to the unconditional normalizeCacheControlTTLOrder(enforceCacheControlBlockLimit(body)). On the 32KB Claude Code benchmark body with thinking, this made the optimized path slightly slower than the pre-fix code (112us vs 104us). Skip the second collectCacheControlPaths pass when the body has no "1h" literal. The walk is provably a no-op there: last1h stays -1 and nothing is rewritten. Escaped bodies returned earlier, so the byte check is exact, and the block-limit deletions only remove cache_control keys, which cannot introduce a 1h breakpoint. Benchmark (Apple M5 Pro, -benchtime 2s -count 3): thinking, no 1h: 112us / 21 allocs -> 52us / 8 allocs common, no 1h: 21.6us / 0 allocs -> 21.3us / 0 allocs 1h bodies: unchanged (within noise) The benchmark gains two thinking cases so future work cannot regress this shape unnoticed. Equivalence tests compare against the verbatim legacy implementation. Fixes #8861 Refs #8668