perf: JSON log formatter tests serializability of every field on every log call #96
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#96
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
utils/logging.pyJSONFormatter.format()(lines 93–101) iterates allrecord.__dict__keys (20–30 per record) and callsjson.dumps(value)on each one to test if it's JSON-serializable. This full serialization pass is done just to test — the result is discarded. It runs on every single log call across the entire bot.With
@logged_commandlogging start + end for every command, cache decorator debug logs, and background task loops, this adds up significantly.Fix
Replace serialization test with a type check fast path:
Or use a custom
defaultfunction in the finaljson.dumps()call to handle non-serializable types during actual serialization.Impact
MEDIUM — This is the highest-frequency overhead in the bot. Every log line pays this cost.
PR #109 opened: #109
Replaced the
json.dumps(value)serialization probe with anisinstance()type-check fast path. The constant_SERIALIZABLE_TYPESis defined at module level to avoid tuple recreation on every log call. 935 tests pass.