-
Notifications
You must be signed in to change notification settings - Fork 615
[PERFORMANCE]: Precompile regex patterns across plugins #1834
Copy link
Copy link
Labels
SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseP2: Important but not vital; high-value items that are not crucial for the immediate releaseperformancePerformance related itemsPerformance related items
Milestone
Description
Summary
Multiple plugins compile regex patterns at runtime per invocation. Precompiling during plugin initialization reduces CPU overhead.
Evidence (current code)
plugins/regex_filter/search_replace.py:re.subwith pattern strings per payload value.plugins/sql_sanitizer/sql_sanitizer.py:_strip_sql_comments/_find_issuesuse pattern strings per call.plugins/html_to_markdown/html_to_markdown.py:_strip_tagsuses many inline regexes.plugins/markdown_cleaner/markdown_cleaner.py:_clean_mduses inline regexes.plugins/json_repair/json_repair.py:_repairuses inline regexes per attempt.plugins/argument_normalizer/argument_normalizer.py:_merge_overridesusesre.searchwith string patterns.plugins/code_safety_linter/code_safety_linter.py:tool_post_invokeuses inline regex patterns.plugins/content_moderation/content_moderation.py: custom patterns usere.search/re.findallper request.plugins/virus_total_checker/virus_total_checker.py: URL and allow/deny patterns compiled per hook.
Impact
- CPU overhead per plugin invocation; scales with request rate and payload size.
Proposed fix
- Precompile regex patterns during plugin initialization or config load.
- Store compiled
re.Patternobjects in plugin state/config and reuse per invocation.
Acceptance criteria
- No per-request
re.compilein the above plugins. - Same matching behavior and output.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releaseP2: Important but not vital; high-value items that are not crucial for the immediate releaseperformancePerformance related itemsPerformance related items