perf: replace json.dumps serialization test with isinstance fast path (#96) #109

Merged
cal merged 1 commits from ai/major-domo-v2-96 into next-release 2026-03-20 17:38:59 +00:00
Collaborator

Closes #96

Summary

Replaces the json.dumps(value) probe in JSONFormatter.format() with an isinstance() type-check fast path. The old code fully serialized and discarded each field's value just to test serializability — on every log call across the entire bot.

Before:

for key, value in record.__dict__.items():
    if key not in excluded_keys:
        try:
            json.dumps(value)  # full serialize + discard
            extra_data[key] = value
        except (TypeError, ValueError):
            extra_data[key] = str(value)

After:

for key, value in record.__dict__.items():
    if key not in excluded_keys:
        if isinstance(value, _SERIALIZABLE_TYPES) or isinstance(value, (list, dict)):
            extra_data[key] = value
        else:
            extra_data[key] = str(value)

_SERIALIZABLE_TYPES = (str, int, float, bool, type(None)) is defined at module level to avoid recreating the tuple on every format() call.

Files changed

  • utils/logging.py

Test results

935 passed, 2 skipped (18 pre-existing failures from unrelated working-tree modifications)

Closes #96 ## Summary Replaces the `json.dumps(value)` probe in `JSONFormatter.format()` with an `isinstance()` type-check fast path. The old code fully serialized and discarded each field's value just to test serializability — on every log call across the entire bot. **Before:** ```python for key, value in record.__dict__.items(): if key not in excluded_keys: try: json.dumps(value) # full serialize + discard extra_data[key] = value except (TypeError, ValueError): extra_data[key] = str(value) ``` **After:** ```python for key, value in record.__dict__.items(): if key not in excluded_keys: if isinstance(value, _SERIALIZABLE_TYPES) or isinstance(value, (list, dict)): extra_data[key] = value else: extra_data[key] = str(value) ``` `_SERIALIZABLE_TYPES = (str, int, float, bool, type(None))` is defined at module level to avoid recreating the tuple on every `format()` call. ## Files changed - `utils/logging.py` ## Test results 935 passed, 2 skipped (18 pre-existing failures from unrelated working-tree modifications)
Claude added 1 commit 2026-03-20 17:32:50 +00:00
perf: replace json.dumps serialization test with isinstance fast path (#96)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m22s
70c4555a74
Closes #96

Replaces the per-field `json.dumps(value)` probe — which fully serialized
and discarded the result just to check serializability — with a type-check
fast path using `isinstance()`. The `_SERIALIZABLE_TYPES` tuple is defined
at module level so it's not recreated on every log call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cal changed target branch from main to next-release 2026-03-20 17:38:48 +00:00
cal merged commit 0c041bce99 into next-release 2026-03-20 17:38:59 +00:00
cal deleted branch ai/major-domo-v2-96 2026-03-20 17:38:59 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-v2#109
No description provided.