Skip to content

⚡ Optimize _queue in EBPFDivert using deque#139

Merged
ffalcinelli merged 2 commits into
mainfrom
fix/optimize-ebpf-queue-6355586925287534692
Jun 18, 2026
Merged

⚡ Optimize _queue in EBPFDivert using deque#139
ffalcinelli merged 2 commits into
mainfrom
fix/optimize-ebpf-queue-6355586925287534692

Conversation

@ffalcinelli

Copy link
Copy Markdown
Owner

💡 What: Replaced the underlying data structure of self._queue in pydivert.ebpf.EBPFDivert from a list to a collections.deque. Also changed all pop(0) calls to popleft().
🎯 Why: list.pop(0) has an O(N) time complexity since it requires shifting all subsequent elements in memory. collections.deque.popleft() operates in O(1) time complexity. This improves performance for receiving large batches of packets.
📊 Measured Improvement: In a standalone benchmark popping 100,000 items:

  • List pop(0): ~0.9612s
  • Deque popleft(): ~0.0046s

PR created automatically by Jules for task 6355586925287534692 started by @ffalcinelli

Replaced O(N) `list.pop(0)` with O(1) `deque.popleft()` for `self._queue` in `EBPFDivert` class. Also updated corresponding tests to mock the queue correctly as a deque.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
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.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (f485a4a) to head (64c0f9f).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #139   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files          20       20           
  Lines        2354     2355    +1     
  Branches      217      217           
=======================================
+ Hits         2318     2319    +1     
  Partials       36       36           
Files with missing lines Coverage Δ
pydivert/ebpf.py 96.06% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ffalcinelli ffalcinelli merged commit ced05ce into main Jun 18, 2026
18 checks passed
@ffalcinelli ffalcinelli deleted the fix/optimize-ebpf-queue-6355586925287534692 branch June 18, 2026 11:38
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.

1 participant