Repository navigation
Convert to safe JSON without a closure per call - #746
Merged
Merged
Conversation
The recursive closure formed a reference cycle, so each conversion left three objects for the cyclic garbage collector.
RazerM
force-pushed
the
feature/json-safe-no-closure
branch
from
November 10, 2026 21:56
da069d7 to
b5de7db
Compare
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #746 +/- ##
==========================================
- Coverage 91.76% 91.76% -0.01%
==========================================
Files 49 49
Lines 8153 8151 -2
Branches 622 622
==========================================
- Hits 7482 7480 -2
Misses 538 538
Partials 133 133 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
to_safe_json(), whichLogRecord.to_dict(json_safe=True)uses, defined a nested_convertfunction on every call._convertrefers to itself through its closure, so each call left a function, a cell and a tuple in a reference cycle for the garbage collector.to_safe_json()now calls itself instead.On CPython 3.14,
record.to_dict(json_safe=True)takes 6.7 µs instead of 7.2 µs, and logging through a handler that exports each record that way is about 4% faster.