⚡ Bolt: [performance improvement] Optimize PatternSearcher.PrefixReject#5
⚡ Bolt: [performance improvement] Optimize PatternSearcher.PrefixReject#5nt153133 wants to merge 1 commit into
Conversation
Co-authored-by: nt153133 <[email protected]>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Optimized
PrefixRejectinPatternSearcher.csto use a direct 8-byteulongunaligned memory read even when the prefix length is shorter than 8 bytes, masking out the unused bytes. A fallback slow loop is still retained for bounds safety at the very end of the searched span.🎯 Why: When short byte patterns were passed in to
Search/SearchManythat didn't have an 8-byte minimum prefix,PrefixRejectfell back to manually reading each byte in a slow loop and bit-shifting them into an integer. This added overhead to the hot loop, which executes on nearly every index in the search span. Becausecp.PrefixMaskignores extraneous bits pastprefLen, it's totally safe to read up to 8 bytes and apply the bitmask, as long as an out-of-bounds error is avoided.📊 Impact: Expected ~20-22% performance improvement on short pattern searches.
🔬 Measurement: Measured by creating a 10MB test byte array and running 100 SearchMany iterations over various short patterns, resulting in elapsed time dropping from ~753 ms down to ~586 ms.
PR created automatically by Jules for task 16152097668367746085 started by @nt153133