perf(message_parsing): pre-compile regex patterns for better performance#790
Open
claude[bot] wants to merge 1 commit intomainfrom
Open
perf(message_parsing): pre-compile regex patterns for better performance#790claude[bot] wants to merge 1 commit intomainfrom
claude[bot] wants to merge 1 commit intomainfrom
Conversation
Pre-compile all regex patterns at module level to avoid recompilation overhead on every function call. These functions are used in agent planning and execution paths which are performance-critical. Changes: - Add _THINK_TAGS_RE, _JSON_FENCE_RE, _TRUE_RE, _FALSE_RE, _NULL_RE as module-level pre-compiled patterns - Update remove_think_tags() to use _THINK_TAGS_RE - Update lenient_json_parse() to use pre-compiled patterns - Update extract_json_from_message() to use _JSON_FENCE_RE - Remove unused json_fence_pattern variable Impact: Eliminates regex compilation overhead on every call. For agent workflows processing hundreds of messages, this reduces regex operations from thousands to just 5 initial compilations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
message_parsing.pyto avoid recompilation overhead on every function call_THINK_TAGS_RE,_JSON_FENCE_RE,_TRUE_RE,_FALSE_RE,_NULL_RETest plan
test_message_parsing.py, 23 tests in agent tests)Impact
Eliminates regex compilation overhead on every call to message parsing functions. For agent workflows processing hundreds of messages, this reduces regex operations from thousands to just 5 initial compilations.
🤖 Generated with Claude Code