Skip to content

perf: do not copy and scan the whole body to log 1000 characters of it - #4

Merged
jrosskopf merged 1 commit into
mainfrom
perf/trim-body-redaction
Sep 10, 2026
Merged

jrosskopf merged 1 commit into
mainfrom
perf/trim-body-redaction

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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 reachedSELECT status FROM http_get(...) costs the same as SELECT 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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.
@jrosskopf
jrosskopf merged commit fd6a5fc into main Sep 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant