redaction performance optimization #1
Conversation
This workflow automates the process of uploading a Python package to PyPI when a release is created.
Co-authored-by: YchampionOP <86096030+YchampionOP@users.noreply.github.com>
Summary of ChangesHello @YchampionOP, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the performance of text redaction functionalities within the Highlights
Changelog
Ignored Files
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces significant performance optimizations to the text redaction logic. The changes in _has_mixed_char_types, redact_text, and redact_custom_strings are well-aligned with this goal. Specifically, _has_mixed_char_types is updated to use a single pass over the string, redact_text now uses an efficient join operation for string construction, and redact_custom_strings combines multiple patterns into a single regex for a one-pass scan. My review includes one suggestion for redact_custom_strings to handle cases with overlapping patterns correctly, which is a potential bug that could be addressed.
|
|
||
| count = 0 | ||
| patterns = [] | ||
| for target in strings: |
There was a problem hiding this comment.
When using a combined regex with |, the order of patterns matters. If a shorter string is a substring of a longer one (e.g., "foo" and "foobar"), the regex engine might match the shorter one first, leading to incorrect redaction like "[REDACTED]bar". To prevent this, you should process the strings in descending order of their length. This ensures that longer, more specific strings are matched before their shorter substrings.
| for target in strings: | |
| for target in sorted(strings, key=len, reverse=True): |
Summary
Describe what changed and why.
Changes
Validation
python -m pytest -qRisk and Rollback
Risk level:
Rollback plan: