]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: deduplicate Message-ID in threading + skeleton
authorEric Wong <e@80x24.org>
Mon, 10 Jun 2024 11:34:27 +0000 (11:34 +0000)
committerEric Wong <e@80x24.org>
Tue, 11 Jun 2024 18:37:45 +0000 (18:37 +0000)
xt/perf-threading.t reports a small 0.5-1.0% memory reduction in
non-ancient Perls with CoW strings for threading alone (w/o
rendering the View.pm stuff).

On informal tests using -httpd and giant Linux stable patch set
threads (700+ messages), this ends up being roughly 5MB saved in
/T/ rendering since we use the {mid} field again in the
$ctx->{mapping} table.  This becomes even more beneficial if
handling parallel HTTP requests for messages in the same message
thread, even across different endpoints.

lib/PublicInbox/SearchThread.pm
lib/PublicInbox/View.pm

index 00ae9faccc08b7b16aff259fb9cd54165b485eb2..672c53ad9a9c192ecb5ab6233ac54ab030270d34 100644 (file)
@@ -33,19 +33,24 @@ sub thread {
        # can be shakier if somebody used In-Reply-To with multiple, disparate
        # messages.  So, take the client Date: into account since we can't
        # always determine ordering when somebody uses multiple In-Reply-To.
+       my (%dedupe, $mid);
        my @kids = sort { $a->{ds} <=> $b->{ds} } grep {
                # this delete saves around 4K across 1K messages
                # TODO: move this to a more appropriate place, breaks tests
                # if we do it during psgi_cull
                delete $_->{num};
                bless $_, 'PublicInbox::SearchThread::Msg';
-               if (exists $id_table{$_->{mid}}) {
+               $mid = $_->{mid};
+               if (exists $id_table{$mid}) {
                        $_->{children} = [];
                        push @imposters, $_; # we'll deal with them later
                        undef;
                } else {
                        $_->{children} = {}; # will become arrayref later
-                       $id_table{$_->{mid}} = $_;
+                       %dedupe = ($mid => undef);
+                       ($mid) = keys %dedupe;
+                       $_->{mid} = $mid;
+                       $id_table{$mid} = $_;
                        defined($_->{references});
                }
        } @$msgs;
index 958efa4175fffbba96698be3daadb6fc857ed0a5..dcceb3112ba3af15d376641fa8047cc51738d530 100644 (file)
@@ -432,6 +432,7 @@ sub walk_thread ($$$) {
 
 sub pre_thread  { # walk_thread callback
        my ($ctx, $level, $node, $idx) = @_;
+       # node->{mid} is deduplicated in PublicInbox::SearchThread::thread
        $ctx->{mapping}->{$node->{mid}} = [ '', $node, $idx, $level ];
        skel_dump($ctx, $level, $node);
 }