⚡ Bolt: fast path for data-plane packet classification#61
⚡ Bolt: fast path for data-plane packet classification#61
Conversation
Extracts the dominant case (WireGuard transport data packets) into an explicit `if` check before the `switch` statement in `PacketType.classify` to improve branch prediction and avoid jump table overhead on the hottest path. Also inlines the function. Co-authored-by: igorls <4753812+igorls@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. |
There was a problem hiding this comment.
Pull request overview
Optimizes WireGuard packet classification on the UDP receive hot path by adding a fast-path for transport data packets and encouraging inlining to reduce per-packet overhead.
Changes:
- Added an early
if (msg_type == 4)return for.wg_transportbefore theswitchinPacketType.classify. - Marked
PacketType.classifyasinline. - Documented the optimization rationale in
.jules/bolt.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wireguard/device.zig |
Adds a fast-path branch for transport packets and marks classifier inline to reduce overhead in the hottest path. |
.jules/bolt.md |
Captures the optimization “learning” and recommended action for future hot-path work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing: superseded by docs audit fixes and direct commits to main. See PR #67 (merged) for codec bounds check, and direct commit for timing-safe fix in noise.zig. |
Understood. Acknowledging that this work is now obsolete and stopping work on this task. |
💡 What
Extracted the
msg_type == 4(WireGuard transport data) case inPacketType.classifyinto an explicitifcheck before theswitchstatement, and marked the functioninline.🎯 Why
PacketType.classifyis called on the absolute hottest path: every single incoming UDP packet. Standardswitchstatements compile to jump tables. Since the vast majority of traffic is data-plane packets (type 4), an explicitifcheck allows the CPU to better predict the dominant branch and avoids the overhead of setting up and executing a jump table for every data packet. Inlining further eliminates function call overhead across module boundaries.📊 Impact
Expected improvement: Eliminates a jump table lookup and a function call for every single data-plane packet received, reducing CPU overhead on the main control thread's receive loop.
🔬 How to verify
zig build testzig build -Doptimize=ReleaseFastPR created automatically by Jules for task 14152184934151083494 started by @igorls