user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/3] mbox: halve ->getline "context switches"
Date: Sun,  5 Apr 2020 07:53:48 +0000	[thread overview]
Message-ID: <20200405075349.2173-3-e@yhbt.net> (raw)
In-Reply-To: <20200405075349.2173-1-e@yhbt.net>

We don't need to take extra trips through the event loop for a
single message (in the common case of Message-IDs being unique).
In fact, holding the body reference left behind by Email::Simple
could be harmful to memory usage, though in practice it's not a
big problem since code paths which use Email::MIME take far more.
---
 lib/PublicInbox/Mbox.pm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 3013dc91..d5beceaf 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -44,19 +44,16 @@ sub getline {
 	my ($ctx, $id, $prev, $next, $mref, $hdr) = @$more;
 	if ($hdr) { # first message hits this, only
 		pop @$more; # $hdr
-		return msg_hdr($ctx, $hdr);
-	}
-	if ($mref) { # all messages hit this
 		pop @$more; # $mref
-		return msg_body($$mref);
+		return msg_hdr($ctx, $hdr) . msg_body($$mref);
 	}
 	my $cur = $next or return;
 	my $ibx = $ctx->{-inbox};
 	$next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
 	$mref = $ibx->msg_by_smsg($cur) or return;
 	$hdr = Email::Simple->new($mref)->header_obj;
-	@$more = ($ctx, $id, $prev, $next, $mref); # $next may be undef, here
-	msg_hdr($ctx, $hdr); # all but first message hits this
+	@$more = ($ctx, $id, $prev, $next); # $next may be undef, here
+	msg_hdr($ctx, $hdr) . msg_body($$mref);
 }
 
 sub close {} # noop

  parent reply	other threads:[~2020-04-05  7:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-05  7:53 [PATCH 0/3] some efficiency improvements Eric Wong
2020-04-05  7:53 ` [PATCH 1/3] release large (non ref) scalars using `undef $sv' Eric Wong
2020-04-05  7:53 ` Eric Wong [this message]
2020-04-05  7:53 ` [PATCH 3/3] git: reduce stat buffer storage overhead Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200405075349.2173-3-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).