⚡ Bolt: Optimize packet forwarding with O(1) IP lookup#3
Conversation
Replaces O(N_SWIM) peer lookup with O(N_WG) scan for outgoing packets. This change: 1. Adds `allowed_ip` to `WgPeer` in `src/wireguard/device.zig`. 2. Implements `WgDevice.findByAllowedIp` which scans the active peer list (max 64) instead of the full SWIM membership table (up to 5000). 3. Updates `userspaceEventLoop` in `src/main.zig` to use this efficient lookup. 4. Updates `addPeer` signature and callers. This significantly reduces CPU usage per packet when the mesh is large. 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. |
|
merge conflicts, needs a rebase against main |
Code Review — Action RequiredHey Jules, this PR needs rework before it can be merged. Here are the issues: 1. Redundant lookup method
Fix: In 2. Breaking
|
Understood. I missed that |
|
@jules make sure this is still valid and up to date |
|
Closing due to merge conflicts with v0.7.0 (device.zig FFI tunnel + service filter changes). Please re-evaluate against latest main. |
Understood. Acknowledging that this work is now obsolete and stopping work on this task. I will re-evaluate against the latest main. |
What:
Optimized the hot path for outgoing packet routing by eliminating the linear scan of the SWIM membership table (up to 5000 entries) for every IP packet.
Why:
Packet forwarding is the #1 critical path. Previously,
findPeerByMeshIpiterated over the entire SWIM membership table to find a peer with a matching Mesh IP, then performed another lookup to find the WireGuard session. This was O(N_SWIM).How:
allowed_ipfield toWgPeerstruct (cached from SWIM peer).WgDevice.findByAllowedIpwhich iterates only over theWgDevice.peersarray (fixed size 64).src/main.zigwith this efficient lookup.Impact:
WgPeerstructs.Verification:
zig buildsucceeds.zig test src/wireguard/device.zigpasses relevant tests.zig build testpasses (1 test suite).PR created automatically by Jules for task 10439097791647316204 started by @igorls