Skip to content

Commit 17530b2

Browse files
avargitster
authored andcommitted
perl: nano-optimize by replacing Cwd::cwd() with Cwd::getcwd()
It has been pointed out[1] that cwd() invokes "pwd(1)" while getcwd() is a Perl-native XS function. For what we're using these for we can use getcwd(). The performance difference is miniscule, we're saving on the order of a millisecond or so, see [2] below for the benchmark. I don't think this matters in practice for optimizing git-send-email or perl execution (unlike the patches leading up to this one). But let's do it regardless of that, if only so we don't have to think about this as a low-hanging fruit anymore. 1. https://lore.kernel.org/git/20210512180517.GA11354@dcvr/ 2. $ perl -MBenchmark=:all -MCwd -wE 'cmpthese(10000, { getcwd => sub { getcwd }, cwd => sub { cwd }, pwd => sub { system "pwd >/dev/null" }})' (warning: too few iterations for a reliable count) Rate pwd cwd getcwd pwd 982/s -- -48% -100% cwd 1890/s 92% -- -100% getcwd 10000000000000000000/s 1018000000000000000% 529000000000000064% - Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c95e3a3 commit 17530b2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

git-send-email.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ sub validate_patch {
20202020
require Cwd;
20212021
my $target = Cwd::abs_path($fn);
20222022
# The hook needs a correct cwd and GIT_DIR.
2023-
my $cwd_save = Cwd::cwd();
2023+
my $cwd_save = Cwd::getcwd();
20242024
chdir($repo->wc_path() or $repo->repo_path())
20252025
or die("chdir: $!");
20262026
local $ENV{"GIT_DIR"} = $repo->repo_path();

perl/Git.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ sub command_bidi_pipe {
405405
if ($self) {
406406
shift;
407407
require Cwd;
408-
$cwd_save = Cwd::cwd();
408+
$cwd_save = Cwd::getcwd();
409409
_setup_git_cmd_env($self);
410410
}
411411
require IPC::Open2;

0 commit comments

Comments
 (0)