Performance gain by avoiding arguments check is very small (less then 1%).

Amit amitchoudhary0523@gmail.com
Tue Sep 30 16:40:10 GMT 2025


On Tue, Sep 30, 2025, 8:48 PM Sam James <sam@gentoo.org> wrote:

> Amit <amitchoudhary0523@gmail.com> writes:
>
> > On Tue, Sep 30, 2025, 2:23 AM Wilco Dijkstra <Wilco.Dijkstra@arm.com>
> wrote:
> >
> >  Hi Amit,
> >
> >  Modern compilers will optimize your example code away. You can see that
> >  there are no checks at all in the main function:
> https://godbolt.org/z/aeeTx6zqM
> >
> >  Even if it wasn't optimized, it wouldn't be possible to measure any
> difference.
> >  Running an empty main() in a loop will just measure shell overheads.
> Your
> >  results show it takes a few million cycles per iteration, so an extra
> check cannot
> >  be measured. What you're really measuring is the varying turbo
> frequency of
> >  your laptop...
> >
> >  Benchmarking is hard, much harder than you think. It is  done by
> creating a
> >  tight loop around any code you want to measure. You have to use inputs
> that
> >  are representative of real usage (ideally from traces from actual
> workloads).
> >  For timing we use a high-resolution (nano-second) timer. You can look at
> >  recent benchmarks in benchtests/ that show how it should be done.
> >
> >  Cheers,
> >  Wilco
> >
> > I am not going to get into any discussion because I have learned that
> glibc people are defensive people and they will
> > defend their wrongdoings.
>
> I think Wilco's reply was respectful and professional. It's also
> accurate. I don't see it as defensive at all.
>
> >
> > ------------
>


glibc/POSIX claim that checking arguments of functions lead to
""significant"" performance degradation and that's why they don't validate
the inputs.

But this claim is not proven.

There is no data published by glibc/POSIX as to how much performance is
gained by not validating the input.

In absence of data from glibc/POSIX, I have come to the conclusion that
this claim is false.

I think glibc/POSIX should back up their claim by publishing the test code
and the results so that people can also run the performance tests on their
machines and verify glibc/POSIX claim.

Please don't ask me to do it.

Even if you people don't do it, it is fine with me.

It is your claim and you should prove it.

-------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250930/9ef505a5/attachment-0001.htm>


More information about the Libc-alpha mailing list