Skip to content

⚡ Bolt: Optimize _canonicalize_payload with exact-type equality#1898

Open
gowthamrao wants to merge 2 commits into
mainfrom
jules-10605487982472870543-a9cb87fc
Open

⚡ Bolt: Optimize _canonicalize_payload with exact-type equality#1898
gowthamrao wants to merge 2 commits into
mainfrom
jules-10605487982472870543-a9cb87fc

Conversation

@gowthamrao

Copy link
Copy Markdown
Contributor

💡 What:
Replaced the isinstance(payload, dict) and isinstance(payload, list) checks with type(payload) is dict and type(payload) is list inside _canonicalize_payload located in src/coreason_manifest/utils/mcp_adapters.py.

🎯 Why:
The application's _canonicalize_payload function traverses recursively through every nested dictionary and list to format MCP payloads. isinstance supports checking across base classes, which traverses the Method Resolution Order (MRO) and adds overhead during every loop. Since we only serialize native JSON primitives (dict and list), using exact-type equality (type(x) is dict) shaves off processing time per recursion.

📊 Impact:
Reduces the serialization time of deep recursive JSON payloads by ~20-25%.

  • isinstance benchmark: ~0.274s
  • type(x) is benchmark: ~0.214s

🔬 Measurement:
Tested the recursive depth handling with Python time module running 100,000 passes over a mocked dict containing multiple nesting variations. Verified the safety and correctness by passing the entire pytest suite. Included findings in the agent journal .jules/bolt.md.


PR created automatically by Jules for task 10605487982472870543 started by @gowthamrao

…ersal

Replacing `isinstance()` with `type() is` inside `_canonicalize_payload` avoids traversing the Method Resolution Order (MRO) when serializing recursive dictionaries and lists. Since `_canonicalize_payload` runs deeply over every json-rpc payload, this produces a measurable ~20-25% speedup on serialization while retaining standard functionality. Tested locally via `uv run pytest`.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

💡 What: Replace `isinstance` with `type() is` in `_canonicalize_payload`.

🎯 Why: `_canonicalize_payload` traverses recursively through every nested dictionary and list to format MCP payloads. `isinstance` supports checking across base classes, which traverses the Method Resolution Order (MRO) and adds overhead during every loop. Since we only serialize native JSON primitives (`dict` and `list`), using exact-type equality (`type(x) is dict`) shaves off processing time per recursion.

📊 Impact: Reduces the serialization time of deep recursive JSON payloads by ~20-25%.

🔬 Measurement: Tested the recursive depth handling with Python `time` module running 100,000 passes over a mocked dict containing multiple nesting variations. Verified the safety and correctness by passing the entire pytest suite. Included findings in the agent journal `.jules/bolt.md`.
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