From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] www_coderepo: do not copy {-code_repos} from config
Date: Sun, 8 Jan 2023 08:04:13 +0000 [thread overview]
Message-ID: <20230108080413.4160826-3-e@80x24.org> (raw)
In-Reply-To: <20230108080413.4160826-1-e@80x24.org>
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 '';
prev parent reply other threads:[~2023-01-08 8:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20230108080413.4160826-3-e@80x24.org \
--to=e@80x24.org \
--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).