From: Junio C Hamano <gitster@pobox.com>
To: Subhaditya Nath <sn03.general@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im, sunshine@sunshineco.com
Subject: Re: [PATCH] t7422: fix extra printf argument, eliminate loops
Date: Thu, 10 Apr 2025 05:39:38 -0700 [thread overview]
Message-ID: <xmqqcydkp4vp.fsf@gitster.g> (raw)
In-Reply-To: <20250409191139.29644-2-sn03.general@gmail.com> (Subhaditya Nath's message of "Thu, 10 Apr 2025 00:41:11 +0530")
Subhaditya Nath <sn03.general@gmail.com> writes:
> - for i in $(test_seq 2000)
> - do
> - printf "[submodule \"sm-$i\"]\npath = recursive-submodule-path-$i\n" "$i" ||
> - return 1
> - done >gitmodules &&
> + printf "[submodule \"sm-%d\"]\npath = recursive-submodule-path-%d\n" \
> + $(test_seq 2000 | sed p) >gitmodules &&
> BLOB=$(git hash-object -w --stdin <gitmodules) &&
>
> printf "100644 blob $BLOB\t.gitmodules\n" >tree &&
> - for i in $(test_seq 2000)
> - do
> - printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" "$i" ||
> - return 1
> - done >>tree &&
> + printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" \
> + $(test_seq 2000) >>tree &&
> TREE=$(git mktree <tree) &&
>
> COMMIT=$(git commit-tree "$TREE") &&
Other than the cuteness value (in other words, "by rewriting this
way, I can use this shiny fun feature `printf` has that I just
learned about"), I do not see in what way(s) the updated code is
better than what Eric picked as "most natural" among the four
candidates you presented earlier.
If I am not mistaken, the `printf` utility tends to be implemented
as a built-in in modern shells, so it is not like the above rewrite
replaced 2000 fork+exec with a single fork+exec of /usr/bin/printf,
so for those shells, there is no performance based argument to
prefer it. And with shells that do have to fork+exec
/usr/bin/printf, the command line to invoke it once now uses about
18k bytes with the current code that uses 2-thousand submodules.
When somebody wants to extend the test to try with more submodules,
at some point they need to start worring about hitting argv[] limit
of the userspace-kernel interface, and at that point, it is likely
that they have to go back to a for loop, doing something like
i=0
while test "$i" -le 200000
do
printf ... "$i" "$i"
i=$((i+1))
done
Sorry for not spelling "I would not recommend going in that
direction" in all caps in red letters in my earlier message.
prev parent reply other threads:[~2025-04-10 12:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 14:48 [PATCH] t7422: remove extraneous argument to printf Subhaditya Nath
2025-04-03 17:05 ` Eric Sunshine
2025-04-09 16:19 ` Junio C Hamano
2025-04-09 16:29 ` Subhaditya Nath
2025-04-09 16:32 ` Subhaditya Nath
2025-04-09 17:00 ` Eric Sunshine
2025-04-09 18:06 ` Junio C Hamano
2025-04-09 19:11 ` [PATCH] t7422: fix extra printf argument, eliminate loops Subhaditya Nath
2025-04-09 19:11 ` Subhaditya Nath
2025-04-10 12:39 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqcydkp4vp.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
--cc=sn03.general@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).