user/dev discussion of public-inbox itself
 help / Atom feed
* [PATCH 0/4] HTML micro-optimizations
@ 2016-12-24 11:52 Eric Wong
  2016-12-24 11:52 ` [PATCH 1/4] view: remove unused parameter Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2016-12-24 11:52 UTC (permalink / raw)
  To: meta

Testing with a horriblely long 368-message thread on git@vger,
I've found some minor tweaks which give us some tiny speedups.
Unfortunately, these are minor and new features may end up
costing us more in the future.  Further optimizations are
needed.

Eric Wong (4):
      view: remove unused parameter
      view: stop chomping off whitespace at ends of messages
      view: do not modify array during iteration
      linkify: modify argument in place

 lib/PublicInbox/Linkify.pm | 17 +++++++----------
 lib/PublicInbox/View.pm    | 21 +++++++++------------
 2 files changed, 16 insertions(+), 22 deletions(-)


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* [PATCH 1/4] view: remove unused parameter
  2016-12-24 11:52 [PATCH 0/4] HTML micro-optimizations Eric Wong
@ 2016-12-24 11:52 ` Eric Wong
  2016-12-24 11:52 ` [PATCH 2/4] view: stop chomping off whitespace at ends of messages Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-12-24 11:52 UTC (permalink / raw)
  To: meta

And add a comment about it to remind our future selves.
---
 lib/PublicInbox/View.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index b779665..cf40b55 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -441,7 +441,7 @@ sub attach_link ($$$$;$) {
 
 sub add_text_body {
 	my ($upfx, $p) = @_; # from msg_iter: [ Email::MIME, depth, @idx ]
-	my ($part, $depth, @idx) = @$p;
+	my ($part, $depth) = @$p; # attachment @idx is unused
 	my $ct = $part->content_type || 'text/plain';
 	my $fn = $part->filename;
 
-- 
EW


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* [PATCH 2/4] view: stop chomping off whitespace at ends of messages
  2016-12-24 11:52 [PATCH 0/4] HTML micro-optimizations Eric Wong
  2016-12-24 11:52 ` [PATCH 1/4] view: remove unused parameter Eric Wong
@ 2016-12-24 11:52 ` Eric Wong
  2016-12-24 11:52 ` [PATCH 3/4] view: do not modify array during iteration Eric Wong
  2016-12-24 11:52 ` [PATCH 4/4] linkify: modify argument in place Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-12-24 11:52 UTC (permalink / raw)
  To: meta

This allows a 3-4% speedup in $MESSAGE_ID/T/ page generation
speed for a 368+ message thread.  It also more faithfully
preserves the message as intended; even if the it makes the
sender look like a space-wasting slob :P
---
 lib/PublicInbox/View.pm | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index cf40b55..97a8bcb 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -490,15 +490,13 @@ sub add_text_body {
 		}
 	}
 
-	my $end = "\n";
-	if (@quot) {
-		$end = '';
+	if (@quot) { # ugh, top posted
 		flush_quote(\$s, $l, \@quot);
+	} elsif ($s =~ /\n\z/s) { # common, last line ends with a newline
+		$s;
+	} else { # some editors don't do newlines...
+		$s .= "\n";
 	}
-	$s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
-	$s =~ s/\A\n+//s; # kill leading blank lines
-	$s =~ s/\s+\z//s; # kill all trailing spaces
-	$s .= $end;
 }
 
 sub _msg_html_prepare {
-- 
EW


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* [PATCH 3/4] view: do not modify array during iteration
  2016-12-24 11:52 [PATCH 0/4] HTML micro-optimizations Eric Wong
  2016-12-24 11:52 ` [PATCH 1/4] view: remove unused parameter Eric Wong
  2016-12-24 11:52 ` [PATCH 2/4] view: stop chomping off whitespace at ends of messages Eric Wong
@ 2016-12-24 11:52 ` Eric Wong
  2016-12-24 11:52 ` [PATCH 4/4] linkify: modify argument in place Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-12-24 11:52 UTC (permalink / raw)
  To: meta

This results in a half percent speedup or so doing
$MESSAGE_ID/T/ HTML generation for a 368 message thread.
---
 lib/PublicInbox/View.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 97a8bcb..39ca959 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -476,7 +476,7 @@ sub add_text_body {
 	}
 	my @quot;
 	my $l = PublicInbox::Linkify->new;
-	while (defined(my $cur = shift @lines)) {
+	foreach my $cur (@lines) {
 		if ($cur !~ /^>/) {
 			# show the previously buffered quote inline
 			flush_quote(\$s, $l, \@quot) if @quot;
-- 
EW


^ permalink raw reply	[flat|threaded] 5+ messages in thread

* [PATCH 4/4] linkify: modify argument in place
  2016-12-24 11:52 [PATCH 0/4] HTML micro-optimizations Eric Wong
                   ` (2 preceding siblings ...)
  2016-12-24 11:52 ` [PATCH 3/4] view: do not modify array during iteration Eric Wong
@ 2016-12-24 11:52 ` Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2016-12-24 11:52 UTC (permalink / raw)
  To: meta

This results in over 1% speedup doing $MESSAGE_ID/T/ HTML
generation for a 368-message thread.
---
 lib/PublicInbox/Linkify.pm | 17 +++++++----------
 lib/PublicInbox/View.pm    |  5 ++---
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm
index acd2a47..8e1728c 100644
--- a/lib/PublicInbox/Linkify.pm
+++ b/lib/PublicInbox/Linkify.pm
@@ -22,11 +22,10 @@ my $LINK_RE = qr{(\()?\b((?:ftps?|https?|nntps?|gopher)://
 		 (?:\#[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%\?]+)?
 		 )}xi;
 
-sub new { bless {}, shift }
+sub new { bless {}, $_[0] }
 
 sub linkify_1 {
-	my ($self, $s) = @_;
-	$s =~ s!$LINK_RE!
+	$_[1] =~ s!$LINK_RE!
 		my $beg = $1 || '';
 		my $url = $2;
 		my $end = '';
@@ -50,19 +49,17 @@ sub linkify_1 {
 
 		# only escape ampersands, others do not match LINK_RE
 		$url =~ s/&/&/g;
-		$self->{$key} = $url;
+		$_[0]->{$key} = $url;
 		$beg . 'PI-LINK-'. $key . $end;
 	!ge;
-	$s;
+	$_[1];
 }
 
 sub linkify_2 {
-	my ($self, $s) = @_;
-
 	# Added "PI-LINK-" prefix to avoid false-positives on git commits
-	$s =~ s!\bPI-LINK-([a-f0-9]{40})\b!
+	$_[1] =~ s!\bPI-LINK-([a-f0-9]{40})\b!
 		my $key = $1;
-		my $url = $self->{$key};
+		my $url = $_[0]->{$key};
 		if (defined $url) {
 			"<a\nhref=\"$url\">$url</a>";
 		} else {
@@ -70,7 +67,7 @@ sub linkify_2 {
 			$key;
 		}
 	!ge;
-	$s;
+	$_[1];
 }
 
 1;
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 39ca959..e4e9d7d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -482,9 +482,8 @@ sub add_text_body {
 			flush_quote(\$s, $l, \@quot) if @quot;
 
 			# regular line, OK
-			$cur = $l->linkify_1($cur);
-			$cur = ascii_html($cur);
-			$s .= $l->linkify_2($cur);
+			$l->linkify_1($cur);
+			$s .= $l->linkify_2(ascii_html($cur));
 		} else {
 			push @quot, $cur;
 		}
-- 
EW


^ permalink raw reply	[flat|threaded] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-24 11:52 [PATCH 0/4] HTML micro-optimizations Eric Wong
2016-12-24 11:52 ` [PATCH 1/4] view: remove unused parameter Eric Wong
2016-12-24 11:52 ` [PATCH 2/4] view: stop chomping off whitespace at ends of messages Eric Wong
2016-12-24 11:52 ` [PATCH 3/4] view: do not modify array during iteration Eric Wong
2016-12-24 11:52 ` [PATCH 4/4] linkify: modify argument in place Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	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

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

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