core_timing: Attempt to reduce heap sifting

This commit is contained in:
Merry 2023-09-13 22:55:54 +01:00
parent 3ad7eec9de
commit f70bafff1a

View File

@ -203,10 +203,23 @@ std::optional<s64> CoreTiming::Advance() {
global_timer = GetGlobalTimeNs().count(); global_timer = GetGlobalTimeNs().count();
while (!event_queue.empty() && event_queue.top().time <= global_timer) { while (!event_queue.empty() && event_queue.top().time <= global_timer) {
Event evt = event_queue.top(); const Event& evt = event_queue.top();
event_queue.pop();
if (const auto event_type{evt.type.lock()}) { if (const auto event_type{evt.type.lock()}) {
if (evt.reschedule_time == 0) {
const auto evt_user_data = evt.user_data;
const auto evt_time = evt.time;
event_queue.pop();
basic_lock.unlock();
event_type->callback(
evt_user_data, evt_time,
std::chrono::nanoseconds{GetGlobalTimeNs().count() - evt_time});
basic_lock.lock();
} else {
basic_lock.unlock(); basic_lock.unlock();
const auto new_schedule_time{event_type->callback( const auto new_schedule_time{event_type->callback(
@ -215,7 +228,6 @@ std::optional<s64> CoreTiming::Advance() {
basic_lock.lock(); basic_lock.lock();
if (evt.reschedule_time != 0) {
const auto next_schedule_time{new_schedule_time.has_value() const auto next_schedule_time{new_schedule_time.has_value()
? new_schedule_time.value().count() ? new_schedule_time.value().count()
: evt.reschedule_time}; : evt.reschedule_time};
@ -227,9 +239,8 @@ std::optional<s64> CoreTiming::Advance() {
next_time = pause_end_time + next_schedule_time; next_time = pause_end_time + next_schedule_time;
} }
auto h{event_queue.emplace(Event{next_time, event_fifo_id++, evt.user_data, event_queue.update(evt.handle, Event{next_time, event_fifo_id++, evt.user_data,
evt.type, next_schedule_time})}; evt.type, next_schedule_time, evt.handle});
(*h).handle = h;
} }
} }