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 6/8] overidx: favor non-OO sub dispatch for internal subs
Date: Fri, 17 Jul 2020 06:31:53 +0000	[thread overview]
Message-ID: <20200717063155.3734-7-e@yhbt.net> (raw)
In-Reply-To: <20200717063155.3734-1-e@yhbt.net>

OO method dispatch was 10-15% slower when I was implementing the
NNTP server.  It also serves as a helpful reminder to the reader
at the callsite as to whether a sub is likely in the same
package as the caller or not.
---
 lib/PublicInbox/OverIdx.pm | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 52f6328e..29c6e0b9 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -180,10 +180,10 @@ sub resolve_mid_to_tid {
 
 sub create_ghost {
 	my ($self, $mid) = @_;
-	my $id = $self->mid2id($mid);
-	my $num = $self->next_ghost_num;
+	my $id = mid2id($self, $mid);
+	my $num = next_ghost_num($self);
 	$num < 0 or die "ghost num is non-negative: $num\n";
-	my $tid = $self->next_tid;
+	my $tid = next_tid($self);
 	my $dbh = $self->{dbh};
 	$dbh->prepare_cached(<<'')->execute($num, $tid);
 INSERT INTO over (num, tid) VALUES (?,?)
@@ -221,7 +221,7 @@ sub link_refs {
 			merge_threads($self, $tid, $ptid);
 		}
 	} else {
-		$tid = defined $old_tid ? $old_tid : $self->next_tid;
+		$tid = defined $old_tid ? $old_tid : next_tid($self);
 	}
 	$tid;
 }
@@ -283,7 +283,7 @@ sub _add_over {
 		merge_threads($self, $$old_tid, $cur_tid);
 	} elsif ($n < 0) { # ghost
 		link_refs($self, $refs, $$old_tid);
-		$self->delete_by_num($n);
+		delete_by_num($self, $n);
 		$$v++;
 	}
 	1;
@@ -295,8 +295,8 @@ sub add_over {
 	my $old_tid;
 	my $vivified = 0;
 
-	$self->begin_lazy;
-	$self->delete_by_num($num, \$old_tid);
+	begin_lazy($self);
+	delete_by_num($self, $num, \$old_tid);
 	foreach my $mid (@$mids) {
 		my $v = 0;
 		each_by_mid($self, $mid, ['tid'], \&_add_over,
@@ -305,7 +305,7 @@ sub add_over {
 		$vivified += $v;
 	}
 	my $tid = $vivified ? $old_tid : link_refs($self, $refs, $old_tid);
-	my $sid = $self->sid($xpath);
+	my $sid = sid($self, $xpath);
 	my $dbh = $self->{dbh};
 	my $sth = $dbh->prepare_cached(<<'');
 INSERT INTO over (num, tid, sid, ts, ds, ddd)
@@ -320,7 +320,7 @@ VALUES (?,?,?,?,?,?)
 INSERT INTO id2num (id, num) VALUES (?,?)
 
 	foreach my $mid (@$mids) {
-		my $id = $self->mid2id($mid);
+		my $id = mid2id($self, $mid);
 		$sth->execute($id, $num);
 	}
 }
@@ -328,7 +328,7 @@ INSERT INTO id2num (id, num) VALUES (?,?)
 sub _remove_oid {
 	my ($self, $smsg, $oid, $nr) = @_;
 	if (!defined($oid) || $smsg->{blob} eq $oid) {
-		$self->delete_by_num($smsg->{num});
+		delete_by_num($self, $smsg->{num});
 		$$nr++;
 	}
 	1;
@@ -339,7 +339,7 @@ sub _remove_oid {
 sub remove_oid {
 	my ($self, $oid, $mid) = @_;
 	my $nr = 0;
-	$self->begin_lazy;
+	begin_lazy($self);
 	each_by_mid($self, $mid, ['ddd'], \&_remove_oid, $oid, \$nr);
 	$nr;
 }
@@ -355,7 +355,7 @@ sub _num_mid0_for_oid {
 sub num_mid0_for_oid {
 	my ($self, $oid, $mid) = @_;
 	my $res = [];
-	$self->begin_lazy;
+	begin_lazy($self);
 	each_by_mid($self, $mid, ['ddd'], \&_num_mid0_for_oid, $oid, $res);
 	@$res, # ($num, $mid0);
 }

  parent reply	other threads:[~2020-07-17  6:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  6:31 [PATCH 0/8] indexing cleanup and code reduction Eric Wong
2020-07-17  6:31 ` [PATCH 1/8] v2: use v5.10.1, parent.pm, drop warnings Eric Wong
2020-07-17  6:31 ` [PATCH 2/8] drop binmode usage Eric Wong
2020-07-17  6:31 ` [PATCH 3/8] import: use common capitalization for filtering headers Eric Wong
2020-07-17  6:31 ` [PATCH 4/8] with_umask: pass args to callback Eric Wong
2020-07-17  6:31 ` [PATCH 5/8] overidx: each_by_mid: pass self and args to callbacks Eric Wong
2020-07-17  6:31 ` Eric Wong [this message]
2020-07-17  6:31 ` [PATCH 7/8] searchidx: use v5.10.1, parent.pm, drop warnings Eric Wong
2020-07-17  6:31 ` [PATCH 8/8] search: simplify unindexing Eric Wong
2020-07-17  7:25 ` [9/8 PATCH] v2writable: git_hash_raw: avoid $TMPDIR write 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=20200717063155.3734-7-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).