From 3601eee7e9370ea6c84052459c6dc4a97efd3e37 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2020 07:04:15 +0000 Subject: [PATCH] imap: simplify partial fetch structure 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 fffd611b..673e1646 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) { -- 2.44.0