threads / patch / 50973

patcht/perf: depend on perl JSON only when using --codespeed

Subject: [PATCH] t/perf: depend on perl JSON only when using --codespeed

## tl;dr

2 messages between Apr 23, 2019 and Apr 24, 2019. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Jeff King· Apr 23, 2019, 04:34 UTC · lore

Commit 05eb1c37ed (perf/aggregate: implement codespeed JSON output, 2018-01-05) added a dependency on the perl JSON module to show output from aggregate.perl, but we only need it when the user asks for --codespeed output. While the module is pretty common, it's not part of the base system, and this dependency can get in the way of producing the default human-readable output.

Let's bump the "use" down to a "require" in the code path that needs it, which will be interpreted at run-time instead of compile-time. People not using "--codespeed" won't even load the module, and anybody using it should see the same results (including the same perl error if they don't have it).

Note that this skips the importing step, so we'll have to fully qualify our function call. We could accomplish the same thing in other ways. E.g., calling JSON->import() ourselves, or wrapping "use JSON" in an eval. Since there's only one such call, this seems like the least-magical way of doing it.

Signed-off-by: Jeff King <peff@peff.net>
---
This bites me occasionally when running perf tests on many-core work
machines where I can't just "apt-get install libjson-perl". So I finally
decided look into it. :)
 t/perf/aggregate.perl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to t/perf/aggregate.perl +2 −2
diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
index 494907a892..76dd48f890 100755
--- a/t/perf/aggregate.perl
+++ b/t/perf/aggregate.perl
@@ -3,7 +3,6 @@
 use lib '../../perl/build/lib';
 use strict;
 use warnings;
-use JSON;
 use Getopt::Long;
 use Git;
 
@@ -342,7 +341,8 @@ sub print_codespeed_results {
 		}
 	}
 
-	print to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
+	require JSON;
+	print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
 }
 
 binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
-- 
2.21.0.1182.g3590c06d32
Junio C Hamano· Apr 24, 2019, 01:20 UTC · re: Jeff King · lore

Re: [PATCH] t/perf: depend on perl JSON only when using --codespeed

Jeff King <peff@peff.net> writes:
Show 12 quoted lines
> Commit 05eb1c37ed (perf/aggregate: implement codespeed JSON output,
> 2018-01-05) added a dependency on the perl JSON module to show output
> from aggregate.perl, but we only need it when the user asks for
> --codespeed output. While the module is pretty common, it's not part of
> the base system, and this dependency can get in the way of producing the
> default human-readable output.
>
> Let's bump the "use" down to a "require" in the code path that needs it,
> which will be interpreted at run-time instead of compile-time. People
> not using "--codespeed" won't even load the module, and anybody using it
> should see the same results (including the same perl error if they don't
> have it).
Nice.
> This bites me occasionally when running perf tests on many-core work
> machines where I can't just "apt-get install libjson-perl". So I finally
> decided look into it. :)
Thanks.
Show 25 quoted lines
>  t/perf/aggregate.perl | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
> index 494907a892..76dd48f890 100755
> --- a/t/perf/aggregate.perl
> +++ b/t/perf/aggregate.perl
> @@ -3,7 +3,6 @@
>  use lib '../../perl/build/lib';
>  use strict;
>  use warnings;
> -use JSON;
>  use Getopt::Long;
>  use Git;
>  
> @@ -342,7 +341,8 @@ sub print_codespeed_results {
>  		}
>  	}
>  
> -	print to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
> +	require JSON;
> +	print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
>  }
>  
>  binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";

← back to recent threads