Skip to content

perf: remove virtual dispatch from lock_free_queue#17

Open
viknash wants to merge 1 commit into
masterfrom
perf/remove-queue-virtual-dispatch
Open

perf: remove virtual dispatch from lock_free_queue#17
viknash wants to merge 1 commit into
masterfrom
perf/remove-queue-virtual-dispatch

Conversation

@viknash

@viknash viknash commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

All lock_free_queue methods (push_back, pop_front, pop_back, �mpty) were declared �irtual, but every queue object is always accessed through its concrete type — the vtable dispatch was pure overhead on the scheduling hot path.

Changes

  • lockfreequeue.h: Remove �irtual from all lock_free_queue methods; destructor becomes = default\
  • ** askgraph.h**: Remove ask_queue_type::push_back override (it only forwarded to super::push_back) — now inherits base directly; remove unused \super\ typedef and virtual destructor

Why this is highest impact / lowest effort

  • Every task steal, dequeue, and enqueue calls pop_front / push_back / �mpty — these are the innermost hot-path operations
  • Virtual dispatch adds one indirect branch per call (prevents inlining + branch prediction), plus an 8-byte vtable pointer per queue object
  • Fix is purely mechanical: delete the \�irtual\ keyword from 4 methods — zero behavior change

Performance

Removing virtual dispatch allows the compiler to:

  1. Inline the queue methods directly into caller sites
  2. Eliminate the indirect branch through the vtable pointer
  3. Enable further optimisations (constant propagation, loop unrolling) that were previously blocked by the opaque virtual call

All lock_free_queue methods (push_back, pop_front, pop_back, empty)
were declared virtual, but every queue object is accessed through its
concrete type — vtable dispatch was pure overhead on the hot path.

Changes:
- Remove `virtual` from all lock_free_queue methods; destructor
  becomes `= default` (no polymorphic deletion needed)
- Remove task_queue_type::push_back override that only forwarded to
  super::push_back — now inherits the base implementation directly
- Remove the now-unused `super` typedef and virtual destructor from
  task_queue_type

This eliminates one indirect branch and one vtable pointer (8 bytes)
per queue instance on every push/pop/empty call in the scheduler loop.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR removes virtual dispatch from the lock_free_queue wrapper and simplifies base_task_graph::task_queue_type, aiming to reduce overhead on the task scheduling hot path by enabling inlining and eliminating vtable-related indirection.

Changes:

  • Remove virtual from lock_free_queue wrapper methods and default the destructor.
  • Simplify base_task_graph::task_queue_type by removing a trivial push_back forwarder, an unused super typedef, and an empty virtual destructor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
include/taskgraph.h Removes a redundant derived override/typedef so the queue type inherits base behavior directly.
include/lockfreequeue.h Removes virtual dispatch from queue wrapper methods (intended perf win on enqueue/dequeue hot paths).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/lockfreequeue.h
Comment on lines +249 to 252
bool pop_front(T &val) { return queue.pop_front(val); }

virtual bool pop_back(T &val) { return queue.pop_front(val); }
bool pop_back(T &val) { return queue.pop_front(val); }

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