From: Eric Wong Date: Tue, 31 Oct 2023 20:42:50 +0000 (+0000) Subject: ds: next_tick: shorten object lifetimes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=196f753fb25447b7e8d61a5c0e4c62b464a8e03d;p=thirdparty%2Fpublic-inbox.git ds: next_tick: shorten object lifetimes Drop reference counts ASAP in case it saves us some memory sooner rather than later. This ought to give us more predictable resource use and ensure OnDestroy callbacks fire sooner. There's no need to use `local' to clobber the arrayref anymore, either. AFAIK, this doesn't fix any known bug, but more predictability will make it easier to debug things going forward. --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 6041c6b54..708fe14d6 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -136,16 +136,12 @@ sub _InitPoller () { sub now () { clock_gettime(CLOCK_MONOTONIC) } sub next_tick () { - local $cur_runq = $nextq or return; + $cur_runq = $nextq or return; $nextq = undef; - for my $obj (@$cur_runq) { + while (my $obj = shift @$cur_runq) { # avoid "ref" on blessed refs to workaround a Perl 5.16.3 leak: # https://rt.perl.org/Public/Bug/Display.html?id=114340 - if (blessed($obj)) { - $obj->event_step; - } else { - $obj->(); - } + blessed($obj) ? $obj->event_step : $obj->(); } }