mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-01 20:10:28 +00:00
LibCore: Exit get_next_timer_expiration() sooner if possible
If we find a timer that needs to be fired immediately, we can stop looking through the remaining timers. This significantly reduces time spent in get_next_timer_expiration() on ACID3. Of course, with a better data structure, we could reduce time spent further. I've left a FIXME about that.
This commit is contained in:
parent
06948df393
commit
1a323ec8d4
Notes:
sideshowbarker
2024-07-17 18:44:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1a323ec8d4
1 changed files with 5 additions and 0 deletions
|
@ -793,6 +793,7 @@ void EventLoopTimer::reload(const Time& now)
|
|||
|
||||
Optional<Time> EventLoop::get_next_timer_expiration()
|
||||
{
|
||||
auto now = Time::now_monotonic_coarse();
|
||||
Optional<Time> soonest {};
|
||||
for (auto& it : *s_timers) {
|
||||
auto& fire_time = it.value->fire_time;
|
||||
|
@ -801,6 +802,10 @@ Optional<Time> EventLoop::get_next_timer_expiration()
|
|||
&& owner && !owner->is_visible_for_timer_purposes()) {
|
||||
continue;
|
||||
}
|
||||
// OPTIMIZATION: If we have a timer that needs to fire right away, we can stop looking here.
|
||||
// FIXME: This whole operation could be O(1) with a better data structure.
|
||||
if (fire_time < now)
|
||||
return now;
|
||||
if (!soonest.has_value() || fire_time < soonest.value())
|
||||
soonest = fire_time;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue