]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: reduce early bare-bones memory use
authorEric Wong <e@80x24.org>
Mon, 26 Sep 2022 10:17:15 +0000 (10:17 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Sep 2022 19:22:04 +0000 (19:22 +0000)
The {-git_path} cache can rely on auto-vivification, and
{alt_st} may not be needed for short-lived repos.  So don't
populate those fields until they're needed, since we can
expect to handle thousands of git repos, too.

lib/PublicInbox/Git.pm

index b2ae75c8ae312042562c35dc568047bc8af49a0e..9140caea9bfb2d9e28177c92795e06f5cc94a2ca 100644 (file)
@@ -66,7 +66,7 @@ sub new {
        $git_dir =~ tr!/!/!s;
        $git_dir =~ s!/*\z!!s;
        # may contain {-tmp} field for File::Temp::Dir
-       bless { git_dir => $git_dir, alt_st => '', -git_path => {} }, $class
+       bless { git_dir => $git_dir }, $class
 }
 
 sub git_path ($$) {
@@ -90,7 +90,7 @@ sub alternates_changed {
 
        # can't rely on 'q' on some 32-bit builds, but `d' works
        my $st = pack('dd', $st[10], $st[7]); # 10: ctime, 7: size
-       return 0 if $self->{alt_st} eq $st;
+       return 0 if ($self->{alt_st} // '') eq $st;
        $self->{alt_st} = $st; # always a true value
 }