git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/8] generate-cmdlist.sh: replace for loop by printf's auto-repeat feature

From
Jeff King <peff@peff.net>
Date
Oct 21, 2021, 14:42 UTC
Message-ID
<YXF8a7OoStzdEwZF@coredump.intra.peff.net>
In-Reply-To
<patch-6.8-e0b11514b8d-20211020T183533Z-avarab@gmail.com>
On Wed, Oct 20, 2021 at 08:39:57PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 26 quoted lines
> From: Johannes Sixt <j6t@kdbg.org>
> 
> This is just a small code reduction. There is a small probability that
> the new code breaks when the category list is empty. But that would be
> noticed during the compile step.
> 
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  generate-cmdlist.sh | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
> index e517c33710a..a1ab2b1f077 100755
> --- a/generate-cmdlist.sh
> +++ b/generate-cmdlist.sh
> @@ -67,10 +67,7 @@ print_command_list () {
>  	while read cmd rest
>  	do
>  		printf "	{ \"$cmd\", $(get_synopsis $cmd), 0"
> -		for cat in $(echo "$rest" | get_category_line)
> -		do
> -			printf " | CAT_$cat"
> -		done
> +		printf " | CAT_%s" $(echo "$rest" | get_category_line)
>  		echo " },"

I think this is fine, but regardless of what happens in patch 7, it's probably worth dropping this get_category_line call. All it does is sort and de-dup the tokens in $rest, but we don't care because we're just OR-ing them together. And of the 3 processes spawned by each loop, it is responsible for 2 of them.

Even if this loop is broken out into individual bits of Makefile snippet, avoiding the extra processes is worth doing.

The patch below gives me:
  $ git show HEAD:generate-cmdlist.sh >generate-cmdlist.sh.old
  $ hyperfine --warmup 1 -L s ,.old -p 'make clean' 'sh generate-cmdlist.sh{s} command-list.txt'
  Benchmark #1: sh generate-cmdlist.sh command-list.txt
    Time (mean ± σ):     591.3 ms ±  31.5 ms    [User: 392.9 ms, System: 243.7 ms]
    Range (min … max):   543.7 ms … 630.6 ms    10 runs
   
  Benchmark #2: sh generate-cmdlist.sh.old command-list.txt
    Time (mean ± σ):      1.236 s ±  0.060 s    [User: 1.100 s, System: 0.556 s]
    Range (min … max):    1.089 s …  1.275 s    10 runs
   
  Summary
    'sh generate-cmdlist.sh command-list.txt' ran
      2.09 ± 0.15 times faster than 'sh generate-cmdlist.sh.old command-list.txt'
---
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index a1ab2b1f07..fab9e6a671 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -67,7 +67,7 @@ print_command_list () {
 	while read cmd rest
 	do
 		printf "	{ \"$cmd\", $(get_synopsis $cmd), 0"
-		printf " | CAT_%s" $(echo "$rest" | get_category_line)
+		printf " | CAT_%s" $rest
 		echo " },"
 	done
 	echo "};"

I think you could also delete get_category_line, as it was inlined in
the other caller.

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 15 of 87 in “Why the Makefile is so eager to re-build & re-link”
  1. Ævar Arnfjörð BjarmasonJun 24, 2021
  2. Jeff KingJun 24, 2021
  3. Ævar Arnfjörð BjarmasonJun 24, 2021
  4. Johannes SixtJun 24, 2021
  5. Ævar Arnfjörð BjarmasonJun 25, 2021
  6. Ævar Arnfjörð BjarmasonJun 25, 2021
  7. Jeff KingJun 29, 2021
  8. 0/8 Makefile: make command-list.h 2-5x as fast with -jNÆvar Arnfjörð Bjarmason, Oct 20, 2021
  9. 1/8 command-list.txt: sort with "LC_ALL=C sort"Ævar Arnfjörð Bjarmason, Oct 20, 2021
  10. 2/8 generate-cmdlist.sh: trivial whitespace changeÆvar Arnfjörð Bjarmason, Oct 20, 2021
  11. 3/8 generate-cmdlist.sh: spawn fewer processesÆvar Arnfjörð Bjarmason, Oct 20, 2021
  12. 4/8 generate-cmdlist.sh: don't call get_categories() from category_list()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  13. 5/8 generate-cmdlist.sh: run "grep | sort", not "sort | grep"Ævar Arnfjörð Bjarmason, Oct 20, 2021
  14. 6/8 generate-cmdlist.sh: replace for loop by printf's auto-repeat featureÆvar Arnfjörð Bjarmason, Oct 20, 2021
  15. Jeff KingOct 21, 2021
  16. Jeff KingOct 21, 2021
  17. 7/8 Makefile: stop having command-list.h depend on a wildcardÆvar Arnfjörð Bjarmason, Oct 20, 2021
  18. Jeff KingOct 21, 2021
  19. Junio C HamanoOct 21, 2021
  20. Øystein WalleOct 21, 2021
  21. 8/8 Makefile: assert correct generate-cmdlist.sh outputÆvar Arnfjörð Bjarmason, Oct 20, 2021
  22. Jeff KingOct 20, 2021
  23. Taylor BlauOct 20, 2021
  24. Ævar Arnfjörð BjarmasonOct 20, 2021
  25. Jeff KingOct 20, 2021
  26. Ævar Arnfjörð BjarmasonOct 21, 2021
  27. Taylor BlauOct 21, 2021
  28. Ævar Arnfjörð BjarmasonOct 22, 2021
  29. Jeff KingOct 21, 2021
  30. Junio C HamanoOct 21, 2021
  31. Ævar Arnfjörð BjarmasonOct 22, 2021
  32. Jeff KingOct 22, 2021
  33. Ævar Arnfjörð BjarmasonOct 22, 2021
  34. Eric SunshineOct 21, 2021
  35. 00/10 Makefile: make generate-cmdlist.sh much fasterÆvar Arnfjörð Bjarmason, Oct 22, 2021
  36. 01/10 command-list.txt: sort with "LC_ALL=C sort"Ævar Arnfjörð Bjarmason, Oct 22, 2021
  37. Junio C HamanoOct 25, 2021
  38. Ævar Arnfjörð BjarmasonOct 25, 2021
  39. Junio C HamanoOct 25, 2021
  40. 02/10 generate-cmdlist.sh: trivial whitespace changeÆvar Arnfjörð Bjarmason, Oct 22, 2021
  41. 03/10 generate-cmdlist.sh: spawn fewer processesÆvar Arnfjörð Bjarmason, Oct 22, 2021
  42. 04/10 generate-cmdlist.sh: don't call get_categories() from category_list()Ævar Arnfjörð Bjarmason, Oct 22, 2021
  43. 05/10 generate-cmdlist.sh: run "grep | sort", not "sort | grep"Ævar Arnfjörð Bjarmason, Oct 22, 2021
  44. 06/10 generate-cmdlist.sh: replace for loop by printf's auto-repeat featureÆvar Arnfjörð Bjarmason, Oct 22, 2021
  45. 07/10 generate-cmdlist.sh: stop sorting category linesÆvar Arnfjörð Bjarmason, Oct 22, 2021
  46. Jeff KingOct 25, 2021
  47. 08/10 generate-cmdlist.sh: do not shell out to "sed"Ævar Arnfjörð Bjarmason, Oct 22, 2021
  48. Jeff KingOct 25, 2021
  49. Jeff KingOct 25, 2021
  50. 10/10 generate-cmdlist.sh: replace "cut", "tr" and "grep" with pure-shellÆvar Arnfjörð Bjarmason, Oct 22, 2021
  51. Junio C HamanoOct 23, 2021
  52. 09/10 generate-cmdlist.sh: replace "grep' invocation with a shell versionÆvar Arnfjörð Bjarmason, Oct 22, 2021
  53. Junio C HamanoOct 23, 2021
  54. Junio C HamanoOct 23, 2021
  55. Taylor BlauOct 22, 2021
  56. Junio C HamanoOct 23, 2021
  57. Jeff KingOct 25, 2021
  58. 00/10 generate-cmdlist.sh: make it (and "make") run fasterÆvar Arnfjörð Bjarmason, Nov 5, 2021
  59. 01/10 command-list.txt: sort with "LC_ALL=C sort"Ævar Arnfjörð Bjarmason, Nov 5, 2021
  60. Junio C HamanoNov 5, 2021
  61. Ævar Arnfjörð BjarmasonNov 6, 2021
  62. Junio C HamanoNov 8, 2021
  63. 02/10 generate-cmdlist.sh: trivial whitespace changeÆvar Arnfjörð Bjarmason, Nov 5, 2021
  64. 03/10 generate-cmdlist.sh: spawn fewer processesÆvar Arnfjörð Bjarmason, Nov 5, 2021
  65. Junio C HamanoNov 5, 2021
  66. Ævar Arnfjörð BjarmasonNov 6, 2021
  67. 04/10 generate-cmdlist.sh: don't call get_categories() from category_list()Ævar Arnfjörð Bjarmason, Nov 5, 2021
  68. 05/10 generate-cmdlist.sh: run "grep | sort", not "sort | grep"Ævar Arnfjörð Bjarmason, Nov 5, 2021
  69. 06/10 generate-cmdlist.sh: replace for loop by printf's auto-repeat featureÆvar Arnfjörð Bjarmason, Nov 5, 2021
  70. 07/10 generate-cmdlist.sh: stop sorting category linesÆvar Arnfjörð Bjarmason, Nov 5, 2021
  71. 08/10 generate-cmdlist.sh: do not shell out to "sed"Ævar Arnfjörð Bjarmason, Nov 5, 2021
  72. 09/10 generate-cmdlist.sh: replace "grep' invocation with a shell versionÆvar Arnfjörð Bjarmason, Nov 5, 2021
  73. 10/10 generate-cmdlist.sh: don't parse command-list.txt thriceÆvar Arnfjörð Bjarmason, Nov 5, 2021
  74. Felipe ContrerasJun 25, 2021
  75. Eric SunshineJun 29, 2021
  76. Øystein WalleJun 24, 2021
  77. Øystein WalleJun 24, 2021
  78. Ævar Arnfjörð BjarmasonJun 25, 2021
  79. Documentation/Makefile: don't re-build on 'git version' changesÆvar Arnfjörð Bjarmason, Jul 2, 2021
  80. Junio C HamanoJul 2, 2021
  81. Ævar Arnfjörð BjarmasonJul 3, 2021
  82. Junio C HamanoJul 5, 2021
  83. Felipe ContrerasJul 3, 2021
  84. Ævar Arnfjörð BjarmasonJul 3, 2021
  85. Felipe ContrerasJul 3, 2021
  86. Junio C HamanoJul 5, 2021
  87. Felipe ContrerasJul 6, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.