{"thread":{"id":"50973","subject":"[PATCH] t/perf: depend on perl JSON only when using --codespeed","startedAt":"2019-04-23T04:34:23Z","lastAt":"2019-04-24T01:20:20Z","messageCount":2,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"374298","messageId":"20190423043419.GA11689@sigill.intra.peff.net","threadId":"50973","inReplyTo":null,"subject":"[PATCH] t/perf: depend on perl JSON only when using --codespeed","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-04-23T04:34:20Z","receivedAt":"2019-04-23T04:34:23Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Commit 05eb1c37ed (perf/aggregate: implement codespeed JSON output,\n2018-01-05) added a dependency on the perl JSON module to show output\nfrom aggregate.perl, but we only need it when the user asks for\n--codespeed output. While the module is pretty common, it's not part of\nthe base system, and this dependency can get in the way of producing the\ndefault human-readable output.\n\nLet's bump the \"use\" down to a \"require\" in the code path that needs it,\nwhich will be interpreted at run-time instead of compile-time. People\nnot using \"--codespeed\" won't even load the module, and anybody using it\nshould see the same results (including the same perl error if they don't\nhave it).\n\nNote that this skips the importing step, so we'll have to fully qualify\nour function call. We could accomplish the same thing in other ways.\nE.g., calling JSON->import() ourselves, or wrapping \"use JSON\" in an\neval. Since there's only one such call, this seems like the\nleast-magical way of doing it.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis bites me occasionally when running perf tests on many-core work\nmachines where I can't just \"apt-get install libjson-perl\". So I finally\ndecided look into it. :)\n\n t/perf/aggregate.perl | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl\nindex 494907a892..76dd48f890 100755\n--- a/t/perf/aggregate.perl\n+++ b/t/perf/aggregate.perl\n@@ -3,7 +3,6 @@\n use lib '../../perl/build/lib';\n use strict;\n use warnings;\n-use JSON;\n use Getopt::Long;\n use Git;\n \n@@ -342,7 +341,8 @@ sub print_codespeed_results {\n \t\t}\n \t}\n \n-\tprint to_json(\\@data, {utf8 => 1, pretty => 1, canonical => 1}), \"\\n\";\n+\trequire JSON;\n+\tprint JSON::to_json(\\@data, {utf8 => 1, pretty => 1, canonical => 1}), \"\\n\";\n }\n \n binmode STDOUT, \":utf8\" or die \"PANIC on binmode: $!\";\n-- \n2.21.0.1182.g3590c06d32\n"},{"id":"374359","messageId":"xmqqd0lc42sz.fsf@gitster-ct.c.googlers.com","threadId":"50973","inReplyTo":"20190423043419.GA11689@sigill.intra.peff.net","subject":"Re: [PATCH] t/perf: depend on perl JSON only when using --codespeed","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-24T01:20:12Z","receivedAt":"2019-04-24T01:20:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Commit 05eb1c37ed (perf/aggregate: implement codespeed JSON output,\n> 2018-01-05) added a dependency on the perl JSON module to show output\n> from aggregate.perl, but we only need it when the user asks for\n> --codespeed output. While the module is pretty common, it's not part of\n> the base system, and this dependency can get in the way of producing the\n> default human-readable output.\n>\n> Let's bump the \"use\" down to a \"require\" in the code path that needs it,\n> which will be interpreted at run-time instead of compile-time. People\n> not using \"--codespeed\" won't even load the module, and anybody using it\n> should see the same results (including the same perl error if they don't\n> have it).\n\nNice.\n\n> This bites me occasionally when running perf tests on many-core work\n> machines where I can't just \"apt-get install libjson-perl\". So I finally\n> decided look into it. :)\n\nThanks.\n\n>  t/perf/aggregate.perl | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl\n> index 494907a892..76dd48f890 100755\n> --- a/t/perf/aggregate.perl\n> +++ b/t/perf/aggregate.perl\n> @@ -3,7 +3,6 @@\n>  use lib '../../perl/build/lib';\n>  use strict;\n>  use warnings;\n> -use JSON;\n>  use Getopt::Long;\n>  use Git;\n>  \n> @@ -342,7 +341,8 @@ sub print_codespeed_results {\n>  \t\t}\n>  \t}\n>  \n> -\tprint to_json(\\@data, {utf8 => 1, pretty => 1, canonical => 1}), \"\\n\";\n> +\trequire JSON;\n> +\tprint JSON::to_json(\\@data, {utf8 => 1, pretty => 1, canonical => 1}), \"\\n\";\n>  }\n>  \n>  binmode STDOUT, \":utf8\" or die \"PANIC on binmode: $!\";\n"}]}