Repository navigation
Speed up default scrubbing pattern matching - #2190
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
📝 WalkthroughWalkthroughThe scrubbing implementation combines default patterns into an optimized regex with a prefix character class. Possibly related PRs
Mergeability Score: ⚪ Minimal · up to The change adds a localized prefilter to speed default scrubbing while preserving custom-pattern behavior, with targeted and full-suite validation reported; no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Compare the prefiltered search against each default pattern in isolation, so a new pattern cannot be silently skipped if its example also contains an earlier default match.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_secret_scrubbing.py`:
- Around line 112-115: Update the callback in the test’s iteration flow to bind
the current scrub_matches list when the callback is created, using a default
argument or callback factory. Preserve appending each match to that iteration’s
list and returning match.value, without closing over the loop-rebound variable.
- Around line 102-103: Update the Unicode fixtures in the secret-scrubbing test
cases to represent the long s and dotless i characters with Unicode escape
sequences instead of literal characters. Preserve the existing case-folding test
values and expected behavior while ensuring Ruff RUF001 passes.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8e0b691b-1880-42a7-bd9d-009294719e28
📒 Files selected for processing (1)
tests/test_secret_scrubbing.py
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)pydantic/platform(auto-detected)pydantic/pydantic(auto-detected)
Use Unicode escapes for the long-s and dotless-i fixtures, and bind the per-iteration match list through a callback factory.
Summary
Why
The previous flat alternation tried every default branch at every string position. Large attribute values, especially values without a sensitive match, spent most of their scrubbing time in
re.Pattern.search.The prefilter rejects positions that cannot begin a default match before evaluating the existing patterns. It does not change the default patterns themselves.
Benchmarks
Median microseconds per
re.Pattern.searchon synthetic JSON attributes:A representative whole-value scrub improved from 3.77 ms to 1.15 ms, a 3.29x speedup.
Validation
uv run pytest tests/test_secret_scrubbing.py -q: 18 passedmake lintmake typecheck