From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8F32D1FBD5 for ; Wed, 10 Jun 2020 07:05:22 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 18/82] imap: simplify partial fetch structure Date: Wed, 10 Jun 2020 07:04:15 +0000 Message-Id: <20200610070519.18252-19-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While the contents of normal %want hash keys are bounded in size, %partial can cause more overhead and lead to repeated sort calls on multi-message fetches. So sort it once and use arrayrefs to make the data structure more compact. --- lib/PublicInbox/IMAP.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index fffd611b3c6..673e1646216 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -569,8 +569,8 @@ sub partial_prepare ($$$) { sub partial_emit ($$$) { my ($self, $partial, $eml) = @_; - for my $k (sort keys %$partial) { - my ($cb, @args) = @{$partial->{$k}}; + for (@$partial) { + my ($k, $cb, @args) = @$_; my ($offset, $len) = splice(@args, -2); # $cb is partial_body|partial_hdr_get|partial_hdr_not my $str = $cb->($eml, @args) // ''; @@ -607,7 +607,14 @@ sub cmd_uid_fetch ($$$;@) { return "$tag BAD param: $att\r\n"; } } - $want{-partial} = \%partial if scalar keys %partial; + + # stabilize partial order for consistency and ease-of-debugging: + if (scalar keys %partial) { + $want{-partial} = [ map { + [ $_, @{$partial{$_}} ] + } sort keys %partial ]; + } + my ($beg, $end); my $msgs = []; if ($range =~ /\A([0-9]+):([0-9]+)\z/s) {