markers: replace regexp with manual scanning in Redact()#36
Merged
dhartunian merged 1 commit intomasterfrom Mar 13, 2026
Merged
markers: replace regexp with manual scanning in Redact()#36dhartunian merged 1 commit intomasterfrom
dhartunian merged 1 commit intomasterfrom
Conversation
Contributor
|
Nice! Thanks for working on this. |
Contributor
|
NIT: The |
9a95ff6 to
3f7b73a
Compare
Replace the regexp-based implementation of RedactableString.Redact() and RedactableBytes.Redact() with manual index-based scanning using bytes.Index and a shared redactBytes() implementation. The new implementation: - Scans for start markers (‹) using Index, then finds the closing marker (›) - Distinguishes hash markers (‹†...›) from regular markers (‹...›) inline - Appends hashes directly to the output buffer via appendHash, avoiding intermediate string allocations - Returns early on the fast path when no markers are present - Unifies string and byte Redact() into a single redactBytes() function - Adds a string-level early return in RedactableString.Redact() to avoid []byte conversion allocations when no markers are present Also adds an exhaustive table-driven test (TestRedact) covering edge cases for both RedactableString and RedactableBytes including empty inputs, unclosed markers, unicode content, and hash marker variations. Benchmark results (Apple M1 Pro): name old time/op new time/op delta RedactCall_RegularRedaction-10 243ns ± 2% 62ns ± 1% -74.48% (p=0.000 n=8+8) RedactCall_HashEnabled-10 376ns ± 1% 162ns ± 4% -56.88% (p=0.000 n=8+8) RedactCall_HashWithSalt-10 447ns ± 2% 222ns ± 4% -50.30% (p=0.000 n=8+8) name old alloc/op new alloc/op delta RedactCall_HashEnabled-10 161B ± 0% 64B ± 0% -60.25% (p=0.000 n=8+8) RedactCall_HashWithSalt-10 161B ± 0% 64B ± 0% -60.25% (p=0.000 n=8+8) RedactCall_RegularRedaction-10 104B ± 0% 64B ± 0% -38.46% (p=0.000 n=8+8) name old allocs/op new allocs/op delta RedactCall_HashEnabled-10 8.00 ± 0% 2.00 ± 0% -75.00% (p=0.000 n=8+8) RedactCall_HashWithSalt-10 8.00 ± 0% 2.00 ± 0% -75.00% (p=0.000 n=8+8) RedactCall_RegularRedaction-10 5.00 ± 0% 2.00 ± 0% -60.00% (p=0.000 n=8+8) Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
3f7b73a to
8dc18d3
Compare
visheshbardia
approved these changes
Mar 13, 2026
Contributor
visheshbardia
left a comment
There was a problem hiding this comment.
@visheshbardia made 1 comment.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on aa-joshi).
Contributor
Author
|
TFTR! |
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.
Replace the regexp-based implementation of RedactableString.Redact() and
RedactableBytes.Redact() with manual index-based scanning using
bytes.Index and a shared redactBytes() implementation.
The new implementation:
intermediate string allocations
[]byte conversion allocations when no markers are present
Also adds an exhaustive table-driven test (TestRedact) covering edge cases
for both RedactableString and RedactableBytes including empty inputs,
unclosed markers, unicode content, and hash marker variations.
Benchmark results (Apple M1 Pro):
Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
This change is