Skip to content

⚡ Bolt: Optimize JSON parsing in extract_tools.py with json.loads fast path#6

Merged
thirdeyenation merged 1 commit intomainfrom
bolt-json-parse-fast-path-12031075815286820875
Apr 1, 2026
Merged

⚡ Bolt: Optimize JSON parsing in extract_tools.py with json.loads fast path#6
thirdeyenation merged 1 commit intomainfrom
bolt-json-parse-fast-path-12031075815286820875

Conversation

@thirdeyenation
Copy link
Copy Markdown
Owner

💡 What: Added a fast path to json_parse_dirty in helpers/extract_tools.py that tries the standard library's json.loads before falling back to the custom, slower DirtyJson parser.
🎯 Why: The custom DirtyJson parser is great for fixing broken LLM output, but it's significantly slower than Python's built-in json module, which is implemented in C. Since most LLM output is valid JSON, we were paying a heavy performance penalty for no reason on the "happy path".
📊 Impact: Significant reduction in CPU time when parsing extracted JSON objects, especially large ones. This is a hot path when extracting tool calls or structured outputs from the LLM.
🔬 Measurement: Can be verified by profiling JSON extraction during heavy tool usage or by running synthetic benchmarks comparing json.loads to DirtyJson.parse_string on large, valid JSON strings.


PR created automatically by Jules for task 12031075815286820875 started by @thirdeyenation

This commit introduces a significant performance optimization to `helpers.extract_tools.json_parse_dirty`.
Before this change, the function always used the custom `DirtyJson.parse_string` parser, which is robust
but computationally expensive for well-formed JSON.
Now, the function attempts to parse the extracted string using the highly-optimized `json.loads` from the
standard library first. It falls back to `DirtyJson.parse_string` only if a `JSONDecodeError` occurs.
This provides a "fast path" for the majority of LLM outputs, which are well-formed JSON, while preserving
the fault-tolerant behavior for edge cases.

A journal entry documenting this codebase-specific performance learning has been added to `.jules/bolt.md`.

Co-authored-by: thirdeyenation <133812267+thirdeyenation@users.noreply.github.com>
@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.

@thirdeyenation thirdeyenation merged commit e67aced into main Apr 1, 2026
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