user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 3/3] git: reduce stat buffer storage overhead
Date: Sun,  5 Apr 2020 07:53:49 +0000	[thread overview]
Message-ID: <20200405075349.2173-4-e@yhbt.net> (raw)
In-Reply-To: <20200405075349.2173-1-e@yhbt.net>

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 {

      parent reply	other threads:[~2020-04-05  7:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-05  7:53 [PATCH 0/3] some efficiency improvements Eric Wong
2020-04-05  7:53 ` [PATCH 1/3] release large (non ref) scalars using `undef $sv' Eric Wong
2020-04-05  7:53 ` [PATCH 2/3] mbox: halve ->getline "context switches" Eric Wong
2020-04-05  7:53 ` 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=20200405075349.2173-4-e@yhbt.net \
    --to=e@yhbt.net \
    --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).