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: https://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 \
    --subject='Re: [PATCH 6/8] overidx: favor non-OO sub dispatch for internal subs' \
    /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

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git