about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-05 08:29:54 +0000
committerEric Wong <e@80x24.org>2022-08-06 06:34:45 +0000
commitd1024533712e32fde9c9812e604661ffc9e79019 (patch)
tree596befe523eeb3d85eb15af9b8d6074d476f20d7 /lib/PublicInbox/Config.pm
parent27876bd1269d18f697847a724a8465318cb3cd67 (diff)
downloadpublic-inbox-d1024533712e32fde9c9812e604661ffc9e79019.tar.gz
This means all Inbox, Git, Over, Msgmap, Search objects also get
deduplicated if they belong to the same config file, reducing
memory and FD usage.  This helps save memory and improve cache
hit rates in -netd setups where NNTP, IMAP, HTTP, and POP3
servers run in the same process.

InboxIdle was the only bit which needed adjustment, but there
may be other bugs lurking despite all tests passing.
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index a31b5b74..ad8b8e9d 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -13,6 +13,7 @@ use v5.10.1;
 use PublicInbox::Inbox;
 use PublicInbox::Spawn qw(popen_rd);
 our $LD_PRELOAD = $ENV{LD_PRELOAD}; # only valid at startup
+our $DEDUPE; # set to {} to dedupe or clear cache
 
 sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] }
 
@@ -22,11 +23,17 @@ sub new {
         my ($class, $file, $errfh) = @_;
         $file //= default_file();
         my $self;
+        my $set_dedupe;
         if (ref($file) eq 'SCALAR') { # used by some tests
                 open my $fh, '<', $file or die;  # PerlIO::scalar
                 $self = config_fh_parse($fh, "\n", '=');
                 bless $self, $class;
         } else {
+                if (-f $file && $DEDUPE) {
+                        $file = rel2abs_collapsed($file);
+                        $self = $DEDUPE->{$file} and return $self;
+                        $set_dedupe = 1;
+                }
                 $self = git_config_dump($class, $file, $errfh);
                 $self->{'-f'} = $file;
         }
@@ -62,7 +69,7 @@ sub new {
         if (my $css = delete $self->{'publicinbox.css'}) {
                 $self->{css} = _array($css);
         }
-
+        $DEDUPE->{$file} = $self if $set_dedupe;
         $self;
 }