perf: Precompile regex patterns across plugins#2343
Merged
crivetimihai merged 1 commit intomainfrom Jan 24, 2026
Merged
Conversation
Precompile all regex patterns at module or configuration initialization time across 14 plugins, eliminating per-request compilation overhead. Closes #1834 Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
713d13b to
49d75e9
Compare
crivetimihai
approved these changes
Jan 24, 2026
Member
Review ChangesRebased onto main and made the following fixes: 1. Fixed Pydantic Deprecation WarningsChanged from deprecated
2. Fixed Logic Bug in
|
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
Precompile all regex patterns at module or configuration initialization time across 14 plugins, eliminating per-request compilation overhead. Closes IBM#1834 Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.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.
🚀 Performance Improvement PR
Summary
This PR precompiles all regex patterns at module or configuration initialization time across 14 plugins, eliminating per-request compilation overhead.
🔗 Related Issue
Closes #1834
Changes
Refactored 14 plugins to precompile all regex patterns:
Core Plugins
search_replace.py) - Precompile search patterns in__init__sql_sanitizer.py) - Module-level pattern compilation + config validatorhtml_to_markdown.py) - 15+ module-level precompiled patternsmarkdown_cleaner.py) - 5 module-level precompiled patternsjson_repair.py) - Module-level pattern compilationSecurity & Validation Plugins
argument_normalizer.py) - Module-level + Pydantic validator compilationcode_safety_linter.py) - Default + custom pattern precompilationsecrets_detection.py) - Module-level PATTERNS dictcontent_moderation.py) - Module-level + category pattern compilationharmful_content_detector.py) - Module-level pattern compilationIntegration Plugins
virus_total_checker.py) - URL + allow/deny pattern compilation via validatorstimezone_translator.py) - Module-level ISO timestamp patternsafe_html_sanitizer.py) - Multiple module-level precompiled patternsrobots_license_guard.py) - Module-level META_PATTERNImplementation Patterns
Two primary patterns were used:
1. Module-level compilation
Patterns compiled at import time:
2. Config-time compilation
Patterns compiled via Pydantic validators:
Performance Impact
Benchmark results (1000 iterations each):
Verification
✅ All acceptance criteria met:
re.compile()calls in any pluginPatternobjects✅ Code review completed:
re.sub(),re.search(),re.match(), orre.findall()with string patternsPattern[str]orre.Patternobjects.sub(),.search(),.finditer()on precompiled patterns✅ Testing:
Existing plugin test suites validate: