-
Notifications
You must be signed in to change notification settings - Fork 568
⚡️ Speed up method EventScrubber.scrub_dict by 45%
#4943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
misrasaurabh1
wants to merge
1
commit into
getsentry:master
from
codeflash-ai:codeflash/optimize-EventScrubber.scrub_dict-mg91kjfw
Open
⚡️ Speed up method EventScrubber.scrub_dict by 45%
#4943
misrasaurabh1
wants to merge
1
commit into
getsentry:master
from
codeflash-ai:codeflash/optimize-EventScrubber.scrub_dict-mg91kjfw
+2
−1
Conversation
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
The optimization achieves a **44% speedup** by converting the denylist from a list to a set for lookups while preserving the original list for compatibility. **Key optimization:** - Added `self._denylist_set = set(self.denylist)` in `__init__()` - Changed `k.lower() in self.denylist` to `k.lower() in self._denylist_set` in `scrub_dict()` **Why this works:** - List membership checking (`in` operator) is O(n) - it must scan through each element until found - Set membership checking is O(1) average case - uses hash table for instant lookup - The line profiler shows the lookup line went from 466.1ns per hit to 336.2ns per hit (28% faster per lookup) **Performance impact by test case:** - Most effective on dictionaries with many non-sensitive keys (141% speedup on 1000-key dict) - Significant gains (25-37%) on nested structures and mixed sensitive/non-sensitive data - Minimal overhead on simple cases (empty dicts, single keys) The optimization is particularly beneficial for large dictionaries or applications that frequently scrub data with extensive denylists, as each key check becomes dramatically faster while maintaining identical functionality.
btw i also think that the original self.denylist is not necessary, it should just be a set
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.
📄 45% (0.45x) speedup for
EventScrubber.scrub_dictinsentry_sdk/scrubber.py⏱️ Runtime :
1.17 milliseconds→808 microseconds(best of285runs)📝 Explanation and details
The optimization achieves a 44% speedup by converting the denylist from a list to a set for lookups while preserving the original list for compatibility.
Key optimization:
self._denylist_set = set(self.denylist)in__init__()k.lower() in self.denylisttok.lower() in self._denylist_setinscrub_dict()Why this works:
inoperator) is O(n) - it must scan through each element until foundPerformance impact by test case:
The optimization is particularly beneficial for large dictionaries or applications that frequently scrub data with extensive denylists, as each key check becomes dramatically faster while maintaining identical functionality.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-EventScrubber.scrub_dict-mg91kjfwand push.Codeflash