perf: do not copy and scan the whole body to log 1000 characters of it - #4
Merged
Merged
Conversation
RedactBody was called on every response body, copying it and scanning it several times; the result was then cut to 1000 characters and, when tracing was off, discarded entirely. Measured on a 208 MB page that is a 208 MB copy and roughly 1.6 GB of scanning thrown away on the default path. The call is now guarded on tracing being enabled and takes only the prefix that can actually be logged, so redaction cost is bounded by the log line rather than by the response.
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.
RedactBody(result->body)ran on every response: a full copy of the body plus several linear scans. The result was then truncated to 1000 characters — and when tracing is off (the default) thrown away entirely.Measured on a 208 MB page: a 208 MB copy and roughly 1.6 GB of scanning, discarded.
The call is now guarded on
ErplTracer::Instance().IsEnabled()and takes only the prefix that can actually be logged, so redaction cost is bounded by the log line rather than by the response size.How this was found
A memory investigation for DataZooDE/erpl-web#89 attributed peak RSS by layer and found ~85% of it is committed by the HTTP layer before OData parsing is even reached —
SELECT status FROM http_get(...)costs the same asSELECT length(content), so it is not output materialisation. This was one of the terms inside that 85%.Redaction behaviour is unchanged for anyone who has tracing on: same truncation point, same redaction, verified against a live service.
Verification
Consumer suite: 398 cases / 2053 assertions, green. Tracing still emits a redacted, truncated body; a live 830-row read still returns 830.
Refs DataZooDE/erpl-web#89.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.