-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: change shared_ptrs from copy to reference #2863
base: main
Are you sure you want to change the base?
Conversation
b954f4f
to
4d0a313
Compare
src/game/scheduling/dispatcher.cpp
Outdated
@@ -135,7 +135,7 @@ void Dispatcher::executeScheduledEvents() { | |||
|
|||
if (task->execute() && task->isCycle()) { | |||
task->updateTime(); | |||
threadScheduledTasks.emplace_back(task); | |||
threadScheduledTasks.emplace(task); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollback
src/game/scheduling/dispatcher.cpp
Outdated
if (!thread->tasks[serial].empty()) { | ||
m_tasks[serial].insert(m_tasks[serial].end(), make_move_iterator(thread->tasks[serial].begin()), make_move_iterator(thread->tasks[serial].end())); | ||
thread->tasks[serial].clear(); | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollback
src/game/scheduling/dispatcher.hpp
Outdated
@@ -207,12 +207,11 @@ class Dispatcher { | |||
} | |||
|
|||
std::array<std::vector<Task>, static_cast<uint8_t>(TaskGroup::Last)> tasks; | |||
std::vector<std::shared_ptr<Task>> scheduledTasks; | |||
phmap::parallel_flat_hash_set_m<std::shared_ptr<Task>> scheduledTasks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollback
ef5cdf0
to
d3718ac
Compare
@jhogberg |
src/utils/lockfree.hpp
Outdated
} | ||
return static_cast<T*>(p); | ||
return static_cast<T*>(::operator new(n * sizeof(T), static_cast<std::align_val_t>(alignof(T)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not array-new? new[n] T(…)
src/utils/lockfree.hpp
Outdated
@@ -8,114 +8,62 @@ | |||
*/ | |||
|
|||
#pragma once | |||
#include <atomic_queue/atomic_queue.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? It introduces another layer of complexity that I have a hard time seeing a need for, given how this is currently used.
The per-thread caches are a great idea on their own even without this layer. Is there a reason for the buffers to be recycled across threads?
e176c09
to
6bc24bf
Compare
Quality Gate passedIssues Measures |
This PR is stale because it has been open 45 days with no activity. |
Quality Gate passedIssues Measures |
This PR is stale because it has been open 45 days with no activity. |
Description
This pull request changes multiple instances of
std::shared_ptr
from copies to constant references. This optimization aims to significantly reduce the overhead caused by unnecessary reference count increments and improve performance, especially in critical sections whereshared_ptr
copies were frequently being made.These changes help in avoiding expensive operations related to reference count increments and decrements, thus providing a boost in performance, particularly in loops or commonly accessed functions.
Behaviour
Actual
Unnecessary copies of
shared_ptr
occur frequently, leading to increased reference count management overhead.Expected
The code now uses constant references for
shared_ptr
where appropriate, reducing the number of unnecessary copies and resulting in improved performance.Type of change
How Has This Been Tested
Checklist