Repository navigation
Conversation
sanitizePayloadPII deep-copied every log payload and resolved the PII_RESPONSE_SANITIZATION flag from SQLite once per string, even though the flag is off by default (Hard Rule cheaper-inference#20). The live pending-request preview runs protectPayloadForLog on the full request body at every stage update, so in a production inspector profile (4 x 90 s at peak) these per-string flag lookups were ~32% of the router's main-thread busy time, blocking the event loop for 0.3-2 s on 300-800 KB requests. Resolve the flag once per payload and return the payload untouched when it is off; redactPayload still copies it and describes binary values, so the logged output is unchanged. After deploying this, the same profile showed protectPayloadForLog at 7% of busy time (was 43%) and time spent in event-loop stalls fell from 42% to 11% at matched load.
QuangBlue
force-pushed
the
perf/pii-walk-short-circuit
branch
from
September 27, 2026 04:48
765a609 to
5c93fc2
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a busy instance the event loop stalled for 0.3–2 s per large request (300–800 KB bodies). A production inspector CPU profile taken at peak (4 × 90 s) showed:
isFeatureFlagEnabled("PII_RESPONSE_SANITIZATION"), called fromsanitizePayloadPII.normalizePendingMetadata→protectPayloadForLog. It runs on the full request body at every stage update.Fix
sanitizePayloadPIIresolves the flag once per payload and returns the payload untouched when it is off.redactPayloadstill copies the payload and describes binary values, so the logged output is byte-for-byte the same.Result in production (same profile method, after deploy)
protectPayloadForLog: 43.2% → 7.0% of main-thread busy time; flag lookups: 32.2% → 0.8%.Tests
tests/unit/log-payload-pii-short-circuit.test.ts: with the flag off, the payload is returned without being walked and the logged output is unchanged; enabling the flag through env or the DB override still sanitizes. 2 of its 4 tests fail onrelease/v3.8.51@7d23bcf8e; all 4 pass with the fix.typecheck:core,check-open-sse-typecheckandcheck-api-typecheckshow only the errors already present on the base.