⚡ Bolt: O(N) single-pass answer fragment reassembly - #259
Conversation
Co-authored-by: vamzi <9899519+vamzi@users.noreply.github.com>
|
👋 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:
Refactored the fragmented answer packet reassembly in
decode_answer_fragments_from_packetto use an O(N) single-pass bucket-sort algorithm overpacket.all_resource_records(). It allocates a fixed-size[Option<DecodedFragment>; 256]array on the stack using aconstinitializer to completely avoid heap-allocation orCopy/Clonebounds.🎯 Why:
The original implementation reassembled fragmented DNS answer packets by iteratively calling
collect_single_txtin a loop, walking the packet's resource record list up tochunk_totaltimes. In pathological cases with up to 255 fragments, this led to an O(N²) quadratic time complexity.📊 Impact:
Transforms reassembly performance from O(N²) to O(N) time complexity with zero heap allocations, yielding massive performance gains as the number of fragments increases, while maintaining 100% backward compatibility and exact error propagation.
🔬 Measurement:
Run
cargo test -p openhost-pkarrto execute the comprehensive test suite verifying the optimization's correctness under nominal, malformed, and duplicate fragment scenarios.PR created automatically by Jules for task 12193032883361170609 started by @vamzi