From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Rose via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Seija Kijin <doremylover123@gmail.com>
Subject: Re: [PATCH] diff: use strncmp to check for "diff." prefix
Date: Mon, 19 Dec 2022 19:26:11 +0100 [thread overview]
Message-ID: <221219.86r0wvxmyy.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <pull.1403.git.git.1671467624143.gitgitgadget@gmail.com>
On Mon, Dec 19 2022, Rose via GitGitGadget wrote:
> From: Seija Kijin <doremylover123@gmail.com>
>
> This would be a lot more efficient than
> checking for the full string, as
> so many of the accepted values
> begin with "diff."
>
> This allows the computer to skip most checks
> if var did not start with diff at all.
>
> It would also let us add more "diff." strings
> in the future without having to duplicate
> these 5 character so many times.
This is missing a "why", is this one-off really needed for optimization
purposes? If not it doesn't seem worth the churn.
That we duplicate the "diff." part of "diff.renames" (as opposed to
"renames" is also a feature in my opinion, it makes things easier to
grep for.
It would really just be preferrable to have the compiler do this work
for us. A while ago I experimented with that, i.e. if/else if/else
chains of strcmp(): https://godbolt.org/z/rrnYWW7nj
As that example shows at least GCC doesn't do anything interesting with
it as optimizations are concerned, i.e. you'd really want something like
this instead (but for the compiler to do it for you):
https://godbolt.org/z/7hsPo59TM
But, as you can be seen at https://godbolt.org/z/zWK46rGK5 it *will* do
that if we just use memcmp().
So, doing that really seems preferrable, perhaps with some macro that
would provide the "n" to memcmp, so we wouldn't need to hardcode the
length.
But all of that would be predicated on whether the optimization is
actually worth it.
If we are micro-optimizing config reading we should be moving the
relevant code to the configset API, where we have the parsed keys as a
hash, rather than trying to micro-optimize the callback API, where we'll
call the callback N times, just to brute-force ask it if it's interested
in some small subset of the config space.
prev parent reply other threads:[~2022-12-19 18:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 16:33 [PATCH] diff: use strncmp to check for "diff." prefix Rose via GitGitGadget
2022-12-19 18:26 ` Ævar Arnfjörð Bjarmason [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=221219.86r0wvxmyy.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=doremylover123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.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