perf: remove virtual dispatch from lock_free_queue#17
Open
viknash wants to merge 1 commit into
Open
Conversation
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>
There was a problem hiding this comment.
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
virtualfromlock_free_queuewrapper methods and default the destructor. - Simplify
base_task_graph::task_queue_typeby removing a trivialpush_backforwarder, an unusedsupertypedef, 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 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); } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Why this is highest impact / lowest effort
Performance
Removing virtual dispatch allows the compiler to: