Guard hot-path log calls to avoid payload rendering when disabled#458
Open
mahmoudhas wants to merge 2 commits into
Open
Guard hot-path log calls to avoid payload rendering when disabled#458mahmoudhas wants to merge 2 commits into
mahmoudhas wants to merge 2 commits into
Conversation
Wrap `log.transport()` in `Channel.send()` and `log.runtime()` in `PldRx.decode_pld()` with `log.at_least_level()` checks so that expensive `pformat(payload)` / `repr(msg)` / `repr(pld)` calls are skipped entirely when the respective log level is not active. Previously the f-string arguments were eagerly evaluated before being passed to the log method, even though `StackLevelAdapter.log()` would then discard the message internally via its own `isEnabledFor()` check. On high-frequency IPC paths this caused `pformat` to dominate CPU usage (~60-70 %) as reported in goodboy#455. This also restores the full diagnostic output (msg type, decoded payload) that was temporarily commented out in 0373164 as a stopgap. Resolves goodboy#455
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.
Summary
log.transport()inChannel.send()andlog.runtime()inPldRx.decode_pld()withlog.at_least_level()guards so that expensivepformat(payload)/repr(msg)/repr(pld)rendering is skipped entirely when the respective log level is not active.Fixes #455 — on heavy-payload IPC workload,
py-spyshowedpformat/decode_pldconsuming a significant amount of CPU time.This follows the existing pattern already used elsewhere in the codebase (e.g.
_chan.py:204Channel.connect_from,_context.py:949cancel-scope formatting).Test plan
py-spy topshows no time spent inpformat/_safe_reprwhen running with default log level (ERROR).