Subject: Re: [PATCH 8/9] perl: lazily load some common Git.pm setup code

From: Eric Wong <[email-masked]>
Date: Wed, 12 May 2021 18:05:17 +0000

Ævar Arnfjörð Bjarmason <[email-masked]> wrote:
> @@ -408,10 +404,12 @@ sub command_bidi_pipe {
>  	my $cwd_save = undef;
>  	if ($self) {
>  		shift;
> -		$cwd_save = cwd();
> +		require Cwd;
> +		$cwd_save = Cwd::cwd();
>  		_setup_git_cmd_env($self);

(This also applies to 7/9)

Cwd::cwd() execs /bin/pwd (at least on Perl 5.28.1 in Debian 10x).
There should be a benefit from using Cwd::getcwd() here, instead.

	strace -f -e execve perl -MCwd -E 'Cwd::cwd()

...confirms the execve is happening.

getcwd() takes 25ms vs 27ms of cwd() for me using the
"schedutil" CPU governor under Linux:

	time perl -MCwd -E 'Cwd::getcwd()'
	time perl -MCwd -E 'Cwd::cwd()'