]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: next_tick: shorten object lifetimes
authorEric Wong <e@80x24.org>
Tue, 31 Oct 2023 20:42:50 +0000 (20:42 +0000)
committerEric Wong <e@80x24.org>
Wed, 1 Nov 2023 07:08:08 +0000 (07:08 +0000)
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.

lib/PublicInbox/DS.pm

index 6041c6b549e057091eca385ad38d71a5288c24b0..708fe14d6548bd3d3e28d896126b91649511220e 100644 (file)
@@ -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->();
        }
 }