perf: lift repeated regex compilations to module level#231
Open
vincerevu wants to merge 3 commits intoaiming-lab:mainfrom
Open
perf: lift repeated regex compilations to module level#231vincerevu wants to merge 3 commits intoaiming-lab:mainfrom
vincerevu wants to merge 3 commits intoaiming-lab:mainfrom
Conversation
…332656332533002 perf: lift repeated regex compilations to module level
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
This PR improves regex performance by moving repeatedly compiled patterns to the module level, so they are compiled once at import time instead of on every function call.
What changed
_extract_multi_file_blocksinresearchclaw/pipeline/_helpers.pyto a module-level constant, e.g._MULTI_FILE_PATTERNSWhy
Some regex patterns were being compiled inside function bodies during execution. This means the same patterns could be recompiled many times across repeated calls, adding unnecessary overhead.
Moving these patterns to module scope is a low-risk optimization that:
Scope
This PR focuses only on the
_extract_multi_file_blockspath in:researchclaw/pipeline/_helpers.pyOther possible regex cleanup opportunities were identified, but they are intentionally left out of this PR to keep the change narrow and easy to review.
Validation
Notes
Additional low-risk regex optimizations may be proposed separately for:
_parse_metrics_from_stdoutinresearchclaw/pipeline/_helpers.py_deduplicate_tablesinresearchclaw/templates/converter.py