From b9cc3985078111b1fb38de920fd3b7afe3eec542 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Apr 2020 07:53:49 +0000 Subject: [PATCH] git: reduce stat buffer storage overhead 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 { -- 2.44.0