From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CD8ED1F61B for ; Sun, 5 Apr 2020 07:53:49 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/3] git: reduce stat buffer storage overhead Date: Sun, 5 Apr 2020 07:53:49 +0000 Message-Id: <20200405075349.2173-4-e@yhbt.net> In-Reply-To: <20200405075349.2173-1-e@yhbt.net> References: <20200405075349.2173-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The stat() array is a whopping 480 bytes (on x86-64, Perl 5.28), while the new packed representation of two 64-bit doubles as a scalar is "only" 56 bytes. This can add up when there's many inboxes. Just use a string comparison on the packed representation. Some 32-bit Perl builds (IIRC OpenBSD) lack quad support, so doubles were chosen for pack() portability. --- lib/PublicInbox/Git.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 9c96b3f0..8410b2fc 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -55,10 +55,8 @@ sub git_quote ($) { sub new { my ($class, $git_dir) = @_; - my @st; - $st[7] = $st[10] = 0; # may contain {-tmp} field for File::Temp::Dir - bless { git_dir => $git_dir, st => \@st, -git_path => {} }, $class + bless { git_dir => $git_dir, alt_st => '', -git_path => {} }, $class } sub git_path ($$) { @@ -79,10 +77,11 @@ sub alternates_changed { my ($self) = @_; my $alt = git_path($self, 'objects/info/alternates'); my @st = stat($alt) or return 0; - my $old_st = $self->{st}; - # 10 - ctime, 7 - size - return 0 if ($st[10] == $old_st->[10] && $st[7] == $old_st->[7]); - $self->{st} = \@st; + + # 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; + $self->{alt_st} = $st; # always a true value } sub last_check_err {