user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] coderepo memory savings
@ 2023-01-08  8:04 Eric Wong
  2023-01-08  8:04 ` [PATCH 1/2] config: do not implicitly set coderepo.*.cgiturl Eric Wong
  2023-01-08  8:04 ` [PATCH 2/2] www_coderepo: do not copy {-code_repos} from config Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2023-01-08  8:04 UTC (permalink / raw)
  To: meta

It'll make Data::Dumper-based debugging nicer, too.

Eric Wong (2):
  config: do not implicitly set coderepo.*.cgiturl
  www_coderepo: do not copy {-code_repos} from config

 lib/PublicInbox/Config.pm      |  1 -
 lib/PublicInbox/WwwCoderepo.pm | 16 +++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] config: do not implicitly set coderepo.*.cgiturl
  2023-01-08  8:04 [PATCH 0/2] coderepo memory savings Eric Wong
@ 2023-01-08  8:04 ` Eric Wong
  2023-01-08  8:04 ` [PATCH 2/2] www_coderepo: do not copy {-code_repos} from config Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2023-01-08  8:04 UTC (permalink / raw)
  To: meta

It's a needless waste of memory and this change reduces the
WwwCoderepo object size by over 25% with over 1K repos.
Using the following check:

  perl -MDevel::Size=total_size -I lib -MPublicInbox::WwwCoderepo -E \
  'say total_size(PublicInbox::WwwCoderepo->new(PublicInbox::Config->new))'

before: 1612515
 after: 1184385
---
 lib/PublicInbox/Config.pm | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 174c75ef..c48ab2bd 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -226,7 +226,6 @@ sub cgit_repo_merge ($$$) {
 			$rel =~ s!/?\.git\z!!;
 	}
 	$self->{"coderepo.$rel.dir"} //= $path;
-	$self->{"coderepo.$rel.cgiturl"} //= _array($rel);
 }
 
 sub is_git_dir ($) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] www_coderepo: do not copy {-code_repos} from config
  2023-01-08  8:04 [PATCH 0/2] coderepo memory savings Eric Wong
  2023-01-08  8:04 ` [PATCH 1/2] config: do not implicitly set coderepo.*.cgiturl Eric Wong
@ 2023-01-08  8:04 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2023-01-08  8:04 UTC (permalink / raw)
  To: meta

Avoiding 2 extra hash lookups per-request when we do plenty more
isn't worth the static memory overhead.  This shaves another chunk
off our memory use:

$ perl -MDevel::Size=total_size -I lib -MPublicInbox::WwwCoderepo -E \
  'say total_size(PublicInbox::WwwCoderepo->new(PublicInbox::Config->new))'

before: 1184385
 after: 1020878
---
 lib/PublicInbox/WwwCoderepo.pm | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index 3c929222..7f8b3459 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -49,9 +49,6 @@ sub prepare_coderepos {
 		$pi_cfg->repo_objs($eidx);
 		push @{$self->{-strong}}, $eidx; # strengthen {-ibxs} weakref
 	}
-	while (my ($nick, $repo) = each %$code_repos) {
-		$self->{"\0$nick"} = $repo;
-	}
 }
 
 sub new {
@@ -211,30 +208,31 @@ sub srv { # endpoint called by PublicInbox::WWW
 	my $path_info = $ctx->{env}->{PATH_INFO};
 	my $git;
 	# handle clone requests
+	my $cr = $self->{pi_cfg}->{-code_repos};
 	if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!x) {
-		$git = $self->{"\0$1"} and return
+		$git = $cr->{$1} and return
 			PublicInbox::GitHTTPBackend::serve($ctx->{env},$git,$2);
 	}
 	$path_info =~ m!\A/(.+?)/\z! and
-		($ctx->{git} = $self->{"\0$1"}) and return summary($self, $ctx);
+		($ctx->{git} = $cr->{$1}) and return summary($self, $ctx);
 	$path_info =~ m!\A/(.+?)/([a-f0-9]+)/s/\z! and
-			($ctx->{git} = $self->{"\0$1"}) and
+			($ctx->{git} = $cr->{$1}) and
 		return PublicInbox::ViewVCS::show($ctx, $2);
 
 	# snapshots:
 	if ($path_info =~ m!\A/(.+?)/snapshot/([^/]+)\z! and
-			($ctx->{git} = $self->{"\0$1"})) {
+			($ctx->{git} = $cr->{$1})) {
 		$ctx->{wcr} = $self;
 		return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
 	}
 
 	if ($path_info =~ m!\A/(.+?)/atom/(.*)\z! and
-			($ctx->{git} = $self->{"\0$1"})) {
+			($ctx->{git} = $cr->{$1})) {
 		return PublicInbox::RepoAtom::srv_atom($ctx, $2) // r(404);
 	}
 
 	# enforce trailing slash:
-	if ($path_info =~ m!\A/(.+?)\z! and ($git = $self->{"\0$1"})) {
+	if ($path_info =~ m!\A/(.+?)\z! and ($git = $cr->{$1})) {
 		my $qs = $ctx->{env}->{QUERY_STRING};
 		my $url = $git->base_url($ctx->{env});
 		$url .= "?$qs" if $qs ne '';

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-08  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08  8:04 [PATCH 0/2] coderepo memory savings Eric Wong
2023-01-08  8:04 ` [PATCH 1/2] config: do not implicitly set coderepo.*.cgiturl Eric Wong
2023-01-08  8:04 ` [PATCH 2/2] www_coderepo: do not copy {-code_repos} from config 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).