Repository navigation
Description
What is wrong
The text rules are slow on large files. A pretty-printed MCP tool listing with 10,000 tools is a 3.8 MB file of about 180,000 lines. Scanning it with all 15 rules takes about 3.7 seconds on Python 3.13 (4.4 seconds on 3.9). Parsing the same file with json.loads takes 0.008 seconds, so nearly all the time is in the rules.
Measured per rule on that file (Python 3.9, seconds):
| Rule | Time |
|---|---|
| SG-003 | 0.56 |
| SG-011 | 0.53 |
| SG-009 | 0.45 |
| SG-002 | 0.39 |
| SG-010 | 0.39 |
| SG-007 | 0.36 |
| SG-006 | 0.35 |
| SG-013 | 0.30 |
| SG-001, SG-008 | 0.29 each |
| SG-005 | 0.26 |
| SG-004 | 0.20 |
| SG-012, SG-014, SG-015 | under 0.02 |
This matters more now that SkillShield is starting to scan MCP tool listings (#143), which can be large, and because a scan that gets slower with every new rule becomes a reason to switch it off in CI.
None of these is a denial-of-service problem: the time grows in step with the file size. The aim is a smaller constant.
What done looks like
- A short benchmark script (for example
tests/bench_large_files.py, not run as part of the normal test suite) that builds the 10,000-tool listing above plus a large Markdown file, and prints the time per rule. Include its output, before and after, in the PR. - The slowest rules made faster without changing what they detect. Ideas to try, measured one at a time:
- a cheap plain-text pre-check (for example
"sudo" in text) before running an expensive pattern - combining a rule's many patterns into fewer, or anchoring them on a rare first word
- avoiding a full pass over the text for rules that only need part of it
- a cheap plain-text pre-check (for example
- Every existing test still passes, including the red-team suite and the speed tests for hostile input.
- A combined result on the 10,000-tool listing of under 1.5 seconds on Python 3.12 would be a good target. Report what you reach, even if it falls short.
- One PR per rule or small group of rules is fine, and easier to review.
Found while designing #133.
Before you start, read CONTRIBUTING.md. Comment /assign here to claim the issue.
Activity
cardtable commentedon Nov 20, 2026
/assign
github-actions commentedon Nov 20, 2026
@cardtable it's yours, thanks for picking this up! Please read CONTRIBUTING.md before you start.
If there is no activity from you for 10 days you'll get a reminder, and after 14 days the issue is released for someone else. Any comment from you counts as activity, and an open pull request that mentions this issue pauses the clock. Comment
/extendif you need more time, or/unassignto let it go.docs(changelog): note the SG-011 speed-up (obielin#144)
perf(rules): run SG-011's cheapest check first; add large-file benchm…
perf: lowercase once for the language key-word checks