Skip to content

⚡ Bolt: fast path for data-plane packet classification#61

Closed
igorls wants to merge 1 commit intomainfrom
bolt-packet-classification-fast-path-14152184934151083494
Closed

⚡ Bolt: fast path for data-plane packet classification#61
igorls wants to merge 1 commit intomainfrom
bolt-packet-classification-fast-path-14152184934151083494

Conversation

@igorls
Copy link
Owner

@igorls igorls commented Mar 5, 2026

💡 What

Extracted the msg_type == 4 (WireGuard transport data) case in PacketType.classify into an explicit if check before the switch statement, and marked the function inline.

🎯 Why

PacketType.classify is called on the absolute hottest path: every single incoming UDP packet. Standard switch statements compile to jump tables. Since the vast majority of traffic is data-plane packets (type 4), an explicit if check 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

  1. zig build test
  2. zig build -Doptimize=ReleaseFast

PR created automatically by Jules for task 14152184934151083494 started by @igorls

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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 5, 2026 10:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_transport before the switch in PacketType.classify.
  • Marked PacketType.classify as inline.
  • 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.

@igorls
Copy link
Owner Author

igorls commented Mar 9, 2026

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.

@igorls igorls closed this Mar 9, 2026
@google-labs-jules
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants