user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/7] www: avoid recursion for thread walking
@ 2016-06-21  3:11  7% Eric Wong
  2016-06-21  3:11  5% ` [PATCH 5/7] searchview: remove recursion from thread view Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-06-21  3:11 UTC (permalink / raw)
  To: meta

Deep message threads can cause problems for perl since stack
seems to be much more expensive than arrays.  Switch to a
non-recursive thread walking design and commonalize some
common idioms, too.

Eric Wong (7):
      view: remove upfx parameter from thread skeleton dump
      view: remove dst parameter from thread skeleton dump
      view: remove recursion from thread skeleton dump
      view: remove recursion from expanded thread view
      searchview: remove recursion from thread view
      view: avoid recursion in topic index
      view: common thread walking interface

 lib/PublicInbox/SearchView.pm |  9 ++------
 lib/PublicInbox/View.pm       | 53 +++++++++++++++++++++----------------------
 2 files changed, 28 insertions(+), 34 deletions(-)

^ permalink raw reply	[relevance 7%]

* [PATCH 5/7] searchview: remove recursion from thread view
  2016-06-21  3:11  7% [PATCH 0/7] www: avoid recursion for thread walking Eric Wong
@ 2016-06-21  3:11  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-06-21  3:11 UTC (permalink / raw)
  To: meta

As before, recursion can cause problems sooner than unshifting
objects into the head of a queue.
---
 lib/PublicInbox/SearchView.pm | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 6f67a37..ba25827 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -151,7 +151,6 @@ sub tdump {
 		$m;
 	} ($mset->items);
 
-	my @rootset;
 	my $th = PublicInbox::Thread->new(@m);
 	$th->thread;
 	if ($q->{r}) { # order by relevance
@@ -164,7 +163,6 @@ sub tdump {
 	} else { # order by time (default for threaded view)
 		$th->order(*PublicInbox::View::sort_ts);
 	}
-	@rootset = $th->rootset;
 	my $state = {
 		ctx => $ctx,
 		anchor_idx => 0,
@@ -174,7 +172,13 @@ sub tdump {
 		fh => $fh,
 	};
 	$ctx->{searchview} = 1;
-	tdump_ent($state, $_, 0) for @rootset;
+	my @q = map { (0, $_) } $th->rootset;
+	while (@q) {
+		my $level = shift @q;
+		my $node = shift @q or next;
+		tdump_ent($state, $level, $node);
+		unshift @q, $level+1, $node->child, $level, $node->next;
+	}
 	PublicInbox::View::thread_adj_level($state, 0);
 
 	$fh->write(search_nav_bot($mset, $q). "\n\n" .
@@ -184,8 +188,7 @@ sub tdump {
 }
 
 sub tdump_ent {
-	my ($state, $node, $level) = @_;
-	return unless $node;
+	my ($state, $level, $node) = @_;
 	my $mime = $node->message;
 
 	if ($mime) {
@@ -202,8 +205,6 @@ sub tdump_ent {
 		my $mid = $node->messageid;
 		PublicInbox::View::ghost_flush($state, '', $mid, $level);
 	}
-	tdump_ent($state, $node->child, $level + 1);
-	tdump_ent($state, $node->next, $level);
 }
 
 sub foot {

^ permalink raw reply related	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-21  3:11  7% [PATCH 0/7] www: avoid recursion for thread walking Eric Wong
2016-06-21  3:11  5% ` [PATCH 5/7] searchview: remove recursion from thread view Eric Wong

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).